package com.eactive.eai.rms.onl.common.util;

import org.apache.log4j.Logger;

public class UCMsgSenderUtil {

    public static Logger logger = Logger.getLogger(UCMsgSenderUtil.class);
    
//    private static final String UCINFO           = "UCInfo";
//    private static final String SUBJECT          = "subject";
//    private static final String URL              = "UC.url";
//    private static final String SENDER           = "UC.sender";

    private UCMsgSenderUtil(){
    }
// http://172.19.132.32:12555
//    public static void sendUcMsg( String contents, String recvid, String fileName ){
//		try{
//			
//			if ( recvid == null || recvid.trim().equals("") ) return;
//    		if ( recvid.startsWith("00") ){
//    			recvid = "98" + recvid.substring(2);
//    		}
//
//			Properties prop = PropManager.getInstance().getProperties(UCINFO);
//			String sysGb = "운영";
//			if ( EAIServerManager.getInstance().isDEAIServer() )
//				sysGb = "개발";
//			if ( EAIServerManager.getInstance().isTEAIServer() )
//				sysGb = "검증";
//			String subject = prop.getProperty(SUBJECT) + "<" +sysGb+ ">" + fileName;
//			
//			String Encoding = "UTF-8";
//			String ucUrl = prop.getProperty(URL);
//			String sender = prop.getProperty(SENDER);
//
//			URL url = new URL(ucUrl);
//			HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
//			urlConn.setRequestMethod("POST");
//			urlConn.setDoOutput(true);
//
//			OutputStream os = urlConn.getOutputStream();
//
//
//			BufferedWriter bw1 = new BufferedWriter(new OutputStreamWriter(os));
////			bw1.write("CMD=MSG&Action=ALERT&SystemName=itsm&SendID="+SendID+"&SendName=ITSM&RecvID="+RecvID+"&Subject="+Subject+"&Subject_Encode="+Encoding+"&Contents="+Contents+"&URL="+URL+"&Option=UM=POST,EN=BASE64H,SP=F,LT=20,TP=50,WD=600,HG=520,IT=N,IR=Y");
//			bw1.write("CMD=MSG&Action=ALERT&SystemName=FEP 일괄전송["+sysGb+"]&SendName="+sender+"&RecvID="+recvid+"&Subject="+subject+"&Subject_Encode="+Encoding+"&Contents="+contents+"&Option=UM=POST,EN=BASE64H,SP=F,LT=20,TP=50,WD=600,HG=520,IT=N,IR=Y");
//
//			bw1.flush();
//			bw1.close();
//
//			BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
//			String str = "";
//			while((str = br.readLine()) != null){
//				logger.debug(str);
//			}
//			br.close();
//		}catch(Exception e){
//			logger.error(e.getMessage(), e);
//		}
//    }
//    
//    public static void setUcMsg(BatchJobInfoVO info, String fileName, boolean success, String msg ){
//    	
//    	if ( info == null ) return;
////    	if ( (!info.getRecvNotiUseYn().equals("1")) && success ){
////    		return;
////    	}
//    	if (!info.getRecvNotiUseYn().equals("1")){
//    		return;
//    	}
//    	String procCode = fileName.substring(0, 5);
//    	String instCode = fileName.substring(6, 10);
//    	String procName = "";
//    	String instName = "";
//    	OutsideVO osd = OutsideManager.getInstance().getOutsideInfo(procCode, instCode);
//    	if ( osd != null ){
//    		procName = osd.getBatchName();
//    		instName = osd.getOsdName();
//    	}
//    	String contents = "업무구분명 : " + procName + "<p>" ;
//    	contents += "대외기관명 : " + instName + "<p>" ;
//    	contents += "파일 구분자 : " + info.getJobTranDstcd() + "<p>" ;
//    	contents += "파일    명 : " + fileName + "<p>" ;
//    	contents += "파일  설명 : " + info.getMsgDstName() + "<p>" ;
//    	if ( success ){
//    		contents += "파일 수신에 성공하였습니다.";
//    	}else{
//    		contents += "파일 수신에 성공하였으나 계정계 전송에 실패 하였습니다.<p>";
//    		contents += msg;
//    	}
//
//    	String[] ids = info.getChrgIDs();
//    	for (int inx = 0; inx < ids.length; inx++) {
//    		String recver = ids[inx];
//    		if ( recver == null || recver.trim().equals("") ) return;
//    		if ( info.getRecvUseYN().equals("1") )
//    			sendUcMsg(contents, recver, fileName);
//		}
//    }
    
//    public static void sendMsg(){
//    	
//    	BatchDoc batchDoc = new BatchDoc();
//    	String errMsg = batchDoc.getBatchMsg().getBody().getErrorMsg();
//		CodeMessageVO vo = null;
//		CodeMessageVO nvo = null;
//		
//    	for ( int inx=0; inx < errMsg.length()-12;inx++){
//    		if ( ( vo = CodeMessageManager.getInstance().getMessageVO(errMsg.substring(inx, inx+12))) != null ){
//    			try {
//    				nvo = vo;
//				} catch (Exception e) {}
//    		}
//    	}
//    	
//    	String message = "[송신실패]";
//    	if ( "R".equals(batchDoc.getBatchMsg().getHeader().getProcessType().substring(1,2))){
//    		message = "[수신실패]";
//    	}
//    	message = message + "파일명:" + batchDoc.getBatchMsg().getHeader().getBizCode() 
//        + ",업무명:" + batchDoc.getBatchMsg().getHeader().getProcessName()
//        + ",기관명:" + batchDoc.getBatchMsg().getHeader().getInstitutionName();
//    	if ( nvo != null ) {
//    		message = message + "," + nvo.getMsgEtc();
//    	}
//    	
//    	String procCode = batchDoc.getBatchMsg().getHeader().getProcessCode();
////    	String organCode = batchDoc.getBatchMsg().getHeader().getInstitutionCode();
//    	String bizCode  = batchDoc.getBatchMsg().getHeader().getBizCode();
//    	BatchJobInfoVO jvo = DirInfoManager.getInstance().getFileInfoByDstcd( procCode, bizCode );
//    	String applCd = "";
//    	if ( jvo != null ){
//    		applCd = jvo.getUapplCd();
//    	}
////    	setUcMsg( PropManager.getInstance().getProperty(SMSINFO, REQ_BY_GROUP), applCd, message);
//
//    	// 업무팀이 세팅 되어 있으면 EAI에도 한번 더 보낸다.
//    	if (applCd != null && !applCd.trim().equals("")){
//        	try {
//				if (!PropManager.getInstance().getProperty(SMSINFO, EAI_SEND_YN).trim().equals("")){
////					setUcMsg( PropManager.getInstance().getProperty(SMSINFO, REQ_BY_GROUP), "", message);
//				}
//			} catch (Exception e) {} // 에러 무시
//    	}
//    }
}