PointMigrationInfoCsv.java.svn-base 3.05 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 128 129 130
/**
 *
 */
package jp.agentec.sinaburocast.csv;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import jp.agentec.sinaburocast.common.SinaburoConstant;
import jp.agentec.sinaburocast.entity.Member;
import jp.agentec.sinaburocast.service.MemberService;

import org.seasar.framework.util.StringUtil;
import org.seasar.s2csv.csv.annotation.CSVValidator;
import org.seasar.s2csv.csv.annotation.column.CSVColumn;
import org.seasar.s2csv.csv.annotation.column.CSVRequired;
import org.seasar.s2csv.csv.annotation.entity.CSVEntity;

/**
 * @author choi-c
 *
 */

@CSVEntity(header=true,demiliter='\t',headerCheck=false,columnCountCheck=false)
public class PointMigrationInfoCsv extends AbstractCsv {

	
	public MemberService memberService;
	private int checkMemberId;
	//ポイント付与日時	区分	付加情報	会員ID	メールアドレス	付与ポイント
	@CSVValidator(msgKey = "errors.pointDay", method = "validatePointGetDate")
	@CSVColumn(columnIndex = 0, columnName = "ポイント付与日時")
	public String pointGetDateInput;
	public String pointGetDate;
	
	
	
	@CSVColumn(columnIndex = 1, columnName = "区分")
	public String dummy1;
	
	
	@CSVColumn(columnIndex = 2, columnName = "付加情報")
	public String dummy2;
	
	@CSVValidator(msgKey = "errors.memberId2", method = "validateMemberId")
	@CSVColumn(columnIndex = 3, columnName = "会員ID")
	public String memberId;
	
	
	@CSVColumn(columnIndex = 4, columnName = "メールアドレス")
	public String dummy3;
	
	@CSVRequired
	@CSVColumn(columnIndex = 5, columnName = "付与ポイント")
	public String pointGetNum;
	
	
	@CSVColumn(columnIndex = 6, columnName = "結果")
	public String okNg = "OK";

	@CSVColumn(columnIndex = 7, columnName = "理由")
	public String reason = "reason";
	
	@CSVColumn(columnIndex = 8, columnName = "登録結果")
	public String insertResult = "OK";
	
	
	public Integer pointUseNum=0;	
	public Integer validFlg = SinaburoConstant.ValidFlg.VALID;
	
	
	
	
	
	public boolean validatePointGetDate(String args) {
		Date date = null;
		SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
		if(StringUtil.isBlank(args))
			return true;
		format.setLenient(false);
		
		try {
			date=format.parse(args);
		} catch (ParseException e) {
			return false;
		}
		format = new SimpleDateFormat("yyyyMMdd");
		pointGetDate=format.format(date);
		return true;	
	}
	
	
	public boolean isValidMemberId=false;

	public boolean validateMemberId(String args) {

		if (!StringUtil.equals(args, "")) {
			checkMemberId = Integer.parseInt(args);
		}
		isValidMemberId=validateLoginId(args);
		return isValidMemberId; 
	}

	@SuppressWarnings("unused")
	public boolean validateLoginId(String args) {

		Member memberInfo = null;

		if(StringUtil.isBlank(args)) return true;

		memberInfo = memberService.findById(Integer.parseInt(args));
		if (memberInfo == null) {return false;}
		if (memberInfo != null) {
			if (StringUtil.isBlank(args)) {
				return false;
			}
			if(memberInfo.memberId.equals(checkMemberId)) {
				return true;
			}
			return false;
		}
		return true;
	}
	
		
	
	
	
}