package p2.application.twebcallmethodstatistics;

import baseclass.AppBeanCust;
import com.cnd3b.common.data.db.DBConnect;
import com.cnd3b.common.parameter.parameter;
import p2.p2server.P2Server;
import p2.pao.PaoRemote;
import p2.pao.PaoSetRemote;
import p2.util.P2Exception;
import p2.webclient.system.beans.DataBean;


public class twebcallmethodstatisticsAppBean extends AppBeanCust {

    public int GETMSG() throws P2Exception {
        if (runLongOp("GETMSG")) {
            DBConnect connect = new DBConnect();
            connect.runSqlUpdate("delete from twebcallmethodstatistics");

            PaoSetRemote twebcallmethodstatisticsSet = P2Server.getP2Server().getPaoSet("twebcallmethodstatistics", getPaoSet().getUserInfo());
            for (String key : parameter.callmethodTimes.keySet()) {
                long callmethodTimes = parameter.callmethodTimes.get(key);
                long callmethod_fromcacheTimes = parameter.callmethod_fromcacheTimes.containsKey(key) ? parameter.callmethod_fromcacheTimes.get(key) : 0L;

                PaoRemote pao = twebcallmethodstatisticsSet.addAtEnd();
                pao.setValue("fclassmethod", key, 11L);
                pao.setValue("callmethodtimes", callmethodTimes, 11L);
                pao.setValue("fromdbtimes", callmethodTimes - callmethod_fromcacheTimes, 11L);
                pao.setValue("fromcachetimes", callmethod_fromcacheTimes, 11L);
                pao.setValue("callmethodtimelong", parameter.callmethodTimeLong.get(key), 11L);
                pao.setValue("callmethodtimelongzh", (parameter.callmethodTimeLong.get(key) * (callmethodTimes - callmethod_fromcacheTimes)) / callmethodTimes, 11L);



                pao.setValue("lastcallmethodtime", parameter.lastcallmethodtime.get(key), 11L);
                pao.setValue("callmethodLastTimeLong", parameter.callmethodLastTimeLong.get(key), 11L);

            }
            twebcallmethodstatisticsSet.save();
            twebcallmethodstatisticsSet.close();
        }
        if (LongOpCompleted()) {
            DataBean bean = app.getDataBean("results_showlist");
            bean.reset();
            REFRESH();
        }
        return 1;
    }
}
