package com.eactive.eai.rms.onl.vo;

import java.util.Date;
import java.util.HashMap;

/**
 * The Class TransactionTrackingVo.
 * <ul>
 * <li>1. Function :거래 현황 정보를 구성 한다. </li>
 * <li>2. Summary :</li>
 * <li>3. Notification :</li>
 * </ul>
 * 
 * @author  : $Author: dhlee $
 * @version : $Revision: 1.8.2.1 $
 */
public class TransactionTrackingVo extends MonitorDataVo {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = -8485903467501992391L;

    private String service;

    private Date date;

    /** EAI service code. */
    private String eaiServiceCode;

    /** business code. */
    private String bizCode;

    /** interface type. */
    private String ifType;

    /** The proc100. */
    private int proc100;

    /** The proc200. */
    private int proc200;

    /** The proc300. */
    private int proc300;

    /** The proc400. */
    private int proc400;

    /** The error100. */
    private int error100;

    /** The error200. */
    private int error200;

    /** The error300. */
    private int error300;

    /** The error400. */
    private int error400;

    /** The error900. */
    private int error900;

    /** The timeout error9300. */
    private int error9300;

    /** The timeout error9400. */
    private int error9400;

    /** The timeout error9900. */
    private int error9900;

    /** EAI 평균처리시간. */
    private double timeEai;

    /** 수동시스템 평균처리시간. */
    private double timePsv;

    /** 전체 평균처리시간. */
    private double timeTotal;

    /** 오늘 업무별  거래처리.(업무키->TransactionTrackingVO */
    private HashMap<String, HashMap<String, TransactionTrackingVo>> mapToday;

    /** 최근 10분간 업무별  거래처리.(업무키->TransactionTrackingVO */
    private HashMap<String, HashMap<String, TransactionTrackingVo>> mapRecent;

    private double tps;

    /** 총 거래 건수 */
    private int totalProcAll;

    /** 총 거래 건수 */
    private int totalProc;

    /** 총 에러 건수 */
    private int totalError;

    /** 총 타임아웃 건수 */
    private int totalTimeout;

    private int totalProcAllYesterday;
    private int totalProcYesterday;
    private int totalErrorYesterday;
    private int totalTimeoutYesterday;

    /**
     * @return the totalProcAllYesterday
     */
    public int getTotalProcAllYesterday() {
        return totalProcAllYesterday;
    }

    /**
     * @param totalProcAllYesterday the totalProcAllYesterday to set
     */
    public void setTotalProcAllYesterday(int totalProcAllYesterday) {
        this.totalProcAllYesterday = totalProcAllYesterday;
    }

    /**
     * @return the totalTimeoutYesterday
     */
    public int getTotalTimeoutYesterday() {
        return totalTimeoutYesterday;
    }

    /**
     * @param totalTimeoutYesterday the totalTimeoutYesterday to set
     */
    public void setTotalTimeoutYesterday(int totalTimeoutYesterday) {
        this.totalTimeoutYesterday = totalTimeoutYesterday;
    }

    public int getTotalProcYesterday() {
        return totalProcYesterday;
    }

    public void setTotalProcYesterday(int totalProcYesterday) {
        this.totalProcYesterday = totalProcYesterday;
    }

    public int getTotalErrorYesterday() {
        return totalErrorYesterday;
    }

    public void setTotalErrorYesterday(int totalErrorYesterday) {
        this.totalErrorYesterday = totalErrorYesterday;
    }

    /**
     * @return the ifType
     */
    public String getIfType() {
        return ifType;
    }

    /**
     * @param ifType the ifType to set
     */
    public void setIfType(String ifType) {
        this.ifType = ifType;
    }

    /**
     * Gets the proc100.
     * 
     * @return the proc100
     */
    public int getProc100() {
        return proc100;
    }

    /**
     * Sets the proc100.
     * 
     * @param proc100 the new proc100
     */
    public void setProc100(int proc100) {
        this.proc100 = proc100;
    }

    /**
     * Gets the proc200.
     * 
     * @return the proc200
     */
    public int getProc200() {
        return proc200;
    }

    /**
     * Sets the proc200.
     * 
     * @param proc200 the new proc200
     */
    public void setProc200(int proc200) {
        this.proc200 = proc200;
    }

    /**
     * Gets the proc300.
     * 
     * @return the proc300
     */
    public int getProc300() {
        return proc300;
    }

    /**
     * Sets the proc300.
     * 
     * @param proc300 the new proc300
     */
    public void setProc300(int proc300) {
        this.proc300 = proc300;
    }

    /**
     * Gets the proc400.
     * 
     * @return the proc400
     */
    public int getProc400() {
        return proc400;
    }

    /**
     * Sets the proc400.
     * 
     * @param proc400 the new proc400
     */
    public void setProc400(int proc400) {
        this.proc400 = proc400;
    }

    /**
     * Gets the error100.
     * 
     * @return the error100
     */
    public int getError100() {
        return error100;
    }

    /**
     * Sets the error100.
     * 
     * @param error100 the new error100
     */
    public void setError100(int error100) {
        this.error100 = error100;
    }

    /**
     * Gets the error200.
     * 
     * @return the error200
     */
    public int getError200() {
        return error200;
    }

    /**
     * Sets the error200.
     * 
     * @param error200 the new error200
     */
    public void setError200(int error200) {
        this.error200 = error200;
    }

    /**
     * Gets the error300.
     * 
     * @return the error300
     */
    public int getError300() {
        return error300;
    }

    /**
     * Sets the error300.
     * 
     * @param error300 the new error300
     */
    public void setError300(int error300) {
        this.error300 = error300;
    }

    /**
     * Gets the error400.
     * 
     * @return the error400
     */
    public int getError400() {
        return error400;
    }

    /**
     * Sets the error400.
     * 
     * @param error400 the new error400
     */
    public void setError400(int error400) {
        this.error400 = error400;
    }

    public void addProc100(int value) {
        this.proc100 += value;
    }

    public void addProc200(int value) {
        this.proc200 += value;
    }

    public void addProc300(int value) {
        this.proc300 += value;
    }

    public void addProc400(int value) {
        this.proc400 += value;
    }

    public void addError100(int value) {
        this.error100 += value;
    }

    public void addError200(int value) {
        this.error200 += value;
    }

    public void addError300(int value) {
        this.error300 += value;
    }

    public void addError400(int value) {
        this.error400 += value;
    }

    public void addError900(int value) {
        this.error900 += value;
    }

    public void addError9300(int value) {
        this.error9300 += value;
    }

    public void addError9400(int value) {
        this.error9400 += value;
    }

    public void addError9900(int value) {
        this.error9900 += value;
    }

    public double getTps() {
        return tps;
    }

    public void setTps(double avg) {
        tps = avg;
    }

    public void addTps(double tps) {
        this.tps += tps;
    }

    public int getTotalProc() {
        return totalProc;
    }

    public void setTotalProc(int totalProc) {
        this.totalProc = totalProc;
    }

    public int getTotalError() {
        return totalError;
    }

    public void setTotalError(int totalError) {
        this.totalError = totalError;
    }

    /**
     * @return the totalProcAll
     */
    public int getTotalProcAll() {
        return totalProcAll;
    }

    /**
     * @param totalProcAll the totalProcAll to set
     */
    public void setTotalProcAll(int totalProcAll) {
        this.totalProcAll = totalProcAll;
    }

    /**
     * @return the totalTimeout
     */
    public int getTotalTimeout() {
        return totalTimeout;
    }

    /**
     * @param totalTimeout the totalTimeout to set
     */
    public void setTotalTimeout(int totalTimeout) {
        this.totalTimeout = totalTimeout;
    }

    public void addTotalProcAll(int procAll) {
        this.totalProcAll += procAll;
    }

    public void addTotalTimeout(int timeout) {
        this.totalTimeout += timeout;
    }

    public void addTotalProc(int totalProc) {
        this.totalProc += totalProc;
    }

    public void addTotalError(int totalError) {
        this.totalError += totalError;
    }

    public void addTotalProcYesterday(int totalProcYesterday) {
        this.totalProcYesterday += totalProcYesterday;
    }

    public void addTotalErrorYesterday(int totalErrorYesterday) {
        this.totalErrorYesterday += totalErrorYesterday;
    }

    public void addTotalProcAllYesterday(int totalProcAllYesterday) {
        this.totalProcAllYesterday += totalProcAllYesterday;
    }

    public void addTotalTimeoutYesterday(int totalTimeoutYesterday) {
        this.totalTimeoutYesterday += totalTimeoutYesterday;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * @return the service
     */
    public String getService() {
        return service;
    }

    /**
     * @param service the service to set
     */
    public void setService(String service) {
        this.service = service;
    }

    /**
     * @return the error900
     */
    public int getError900() {
        return error900;
    }

    /**
     * @param error900 the error900 to set
     */
    public void setError900(int error900) {
        this.error900 = error900;
    }

    public int getError9300() {
        return error9300;
    }

    public void setError9300(int error9300) {
        this.error9300 = error9300;
    }

    public int getError9400() {
        return error9400;
    }

    public void setError9400(int error9400) {
        this.error9400 = error9400;
    }

    public int getError9900() {
        return error9900;
    }

    public void setError9900(int error9900) {
        this.error9900 = error9900;
    }

    /**
     * @return the eaiServiceCode
     */
    public String getEaiServiceCode() {
        return eaiServiceCode;
    }

    /**
     * @param eaiServiceCode the eaiServiceCode to set
     */
    public void setEaiServiceCode(String eaiServiceCode) {
        this.eaiServiceCode = eaiServiceCode;
    }

    /**
     * @return the bizCode
     */
    public String getBizCode() {
        return bizCode;
    }

    /**
     * @param bizCode the bizCode to set
     */
    public void setBizCode(String bizCode) {
        this.bizCode = bizCode;
    }

    /**
     * @return the timeEai
     */
    public double getTimeEai() {
        return timeEai;
    }

    /**
     * @param timeEai the timeEai to set
     */
    public void setTimeEai(double timeEai) {
        this.timeEai = timeEai;
    }

    /**
     * @return the timePsv
     */
    public double getTimePsv() {
        return timePsv;
    }

    /**
     * @param timePsv the timePsv to set
     */
    public void setTimePsv(double timePsv) {
        this.timePsv = timePsv;
    }

    /**
     * @return the timeTotal
     */
    public double getTimeTotal() {
        return timeTotal;
    }

    /**
     * @param timeTotal the timeTotal to set
     */
    public void setTimeTotal(double timeTotal) {
        this.timeTotal = timeTotal;
    }

    /**
     * @return the mapToday
     */
    public HashMap<String, HashMap<String, TransactionTrackingVo>> getMapToday() {
        return mapToday;
    }

    /**
     * @param mapToday the mapToday to set
     */
    public void setMapToday(
            HashMap<String, HashMap<String, TransactionTrackingVo>> mapToday) {
        this.mapToday = mapToday;
    }

    /**
     * @param mapToday the mapToday to set
     */
    public void appendMapToday(String bizKey,
            HashMap<String, TransactionTrackingVo> mapToday) {
        if (this.mapToday == null) {
            this.mapToday = new HashMap<String, HashMap<String, TransactionTrackingVo>>();
        }
        this.mapToday.put(bizKey, mapToday);
    }

    /**
     * @return the mapRecent
     */
    public HashMap<String, HashMap<String, TransactionTrackingVo>> getMapRecent() {
        return mapRecent;
    }

    /**
     * @param mapRecent the mapRecent to set
     */
    public void setMapRecent(
            HashMap<String, HashMap<String, TransactionTrackingVo>> mapRecent) {
        this.mapRecent = mapRecent;
    }

    /**
     * @param mapRecent the mapRecent to set
     */
    public void appendMapRecent(String bizKey,
            HashMap<String, TransactionTrackingVo> mapRecent) {
        if (this.mapRecent == null) {
            this.mapRecent = new HashMap<String, HashMap<String, TransactionTrackingVo>>();
        }
        this.mapRecent.put(bizKey, mapRecent);
    }

    /**
     * 
     * @return EAI서비스코드 에 Send/Receive 를 구분하는 Character 를 찾아서 리턴한다.
     */
    public String getSRType() {
        // S/R : left(right(eaiServiceCode,3),1)
        String ret = "";
        if (eaiServiceCode == null || eaiServiceCode.length() < 3) {
            return ret;
        }

        ret = eaiServiceCode.substring(eaiServiceCode.length() - 3);
        return ret.substring(0, 1);
    }

    /**
     * 총건수, 정상건수, 에러건수, 타임아웃 건수를 구한다. ( 전체 합계 계산을 위해 필요함 )
     * 본 함수를 호출하기 전에 먼저, setIfType()  함수를 사용해서 Interface Type 을
     * 초기화 해야 한다.
     */
    public void calcTotalCount() {
        if ("AA".equalsIgnoreCase(getIfType())) {
        	char RType = ' ' ;
        	if( eaiServiceCode != null && eaiServiceCode.length() > 2 ) {
        		RType = eaiServiceCode.charAt(eaiServiceCode.length()-2);        		
        	}
        	if( RType == 'S' || RType == 's' ) {
    			//total = p100 + e100 ;
                setTotalProcAll(getProc100() + getError100());

        	} else { // R,r
    			//total = p300 + e300 ;
                setTotalProcAll(getProc300() + getError300());

    		}
        	
            // A-A 타입 : 에러 건수 = 에러(900)
            setTotalError(getError900());

            // A-A 타입 : 타임아웃 = 타임아웃(900)
            setTotalTimeout(getError9900());

            // 나머지 :  정상 거래건수 = 총건수 - (에러 건수 + 타임아웃)
            setTotalProc(getTotalProcAll() - (getTotalError() + getTotalTimeout()));
            

            // 2008.12.19
            // (보정) 정상건수 가 0 보다 작은경우 : 
            // 날짜 변경선 전에 시작해서 날짜가 지난 후 거래가 끝난 Async 거래.
            // 반복되어서 호출되어도 정상계산되도록 다시 계산한다.
            if( getTotalProc() < 0 ) {
                // totalProcAll -= totalProc
                // totalProc = 0
                setTotalProcAll( getProc100() + getProc300() - getTotalProc() );
                setTotalProc(0);
            }
        } else {
            if( "SA".equalsIgnoreCase(getIfType())) {
                if( getProc100() > 0 && getProc200() == 0 &&
                        getProc300() == 0 && getProc400() == 0 ) {
                    // 2008.12.19 이동훈 차장
                    // S-A 타입이면서 100 에만 값이 존재하는 경우에는 응답 메시지 이므로(이미 카운트에 포함됨 )
                    // 총건수 구하는 식에서 제외시킨다.
                    setTotalProcAll(0);
                    setTotalError(0);
                    setTotalTimeout(0);
                    setTotalProc(0);
                    return ;
                }
            }
            
            // 나머지 : 총건수 = 정상(100) + 에러(100)
            setTotalProcAll(getProc100() + getError100());

            // 나머지  :  에러 건수 = 에러(400) + 에러(900)
            setTotalError(getError400() + getError900());

            // 나머지 : 타임아웃 = 타임아웃(400)
            setTotalTimeout(getError9400());

            // 나머지 :  정상 거래건수 = 총건수 - (에러 건수 + 타임아웃)
            setTotalProc(getTotalProcAll() - (getTotalError() + getTotalTimeout()));
        }
    }
}
