package com.kbstar.eai.flowcontrol.action;

import com.eactive.eai.flowcontrol.action.RouteActionException;
import com.eactive.eai.flowcontrol.action.RouteActionSupport;
import com.eactive.eai.transformer.function.util.CodeConversion;

public class YGSHRouteAction extends RouteActionSupport  {
	
	public String[] getRouteKeys(byte[] message) throws Exception {
		
		String[] keys = new String[1];
		int keyIndex = 0;
		try {
			keys[0] = strncpy(CodeConversion.seToAsc(message), 177, 8);
			
			// 2009.09.07 정길영과장 요청 - ASIS, TOBE //    2010.01.15 권세환대리 요청으로 주석처리
		//	if("50500323".equals(keys[0])) { // 동양증권 자동결재
		//		byte[] keyBytes = new byte[4];
		//		System.arraycopy(message, 158, keyBytes, 0, keyBytes.length);
		//		String keyStr = new String(CodeConversion.seToAsc(keyBytes));
		//		
		//		if("9613".equals(keyStr)) {
		//			keys[0] = keys[0] + "9";
		//		}
		//	}
		//	else
		  	if("50500325".equals(keys[0])) { // 미래에셋증권 자동결재
				byte[] keyBytes = new byte[4];
				System.arraycopy(message, 158, keyBytes, 0, keyBytes.length);
				String keyStr = new String(CodeConversion.seToAsc(keyBytes));
				
				if("9613".equals(keyStr) || 
				   "9617".equals(keyStr)) {
				//	keys[0] = keys[0] + "9";
						keys[0] = keys[0].substring(0,3) + "A" + keys[0].substring(4, keys[0].length());
				}
			}
//			else if("50500312".equals(keys[0])) { // HMC증권 자동결재
//				byte[] keyBytes = new byte[4];
//				System.arraycopy(message, 158, keyBytes, 0, keyBytes.length);
//				String keyStr = new String(CodeConversion.seToAsc(keyBytes));
				
//				if("9613".equals(keyStr)) {
//					keys[0] = keys[0] + "9";
//				}
//			}
			
		} catch(Exception e) {
			throw new RouteActionException(this.getClass().getName() +" Error Extract Key("+keyIndex+"): " +e.getMessage());
		}
        return keys;        
	}
	
	public String getDescription() {
		return "키추출방식 : 전문 [117,8] -> 미래에셋증권자동결재 확인(4번째자리 값을 A로 치환)";
	}
	
//	   public static void main(String args[]) throws Exception {
//	   test();
//}

//	private static void test() throws Exception {
//		String msg = "12345678";
//		msg = msg.substring(0,3) + "A" + msg.substring(4, msg.length());
//		System.out.println(msg);
//		
//		YGSHRouteAction action = new YGSHRouteAction();
//		System.out.println(action.getDescription());
//	}
	
}
