Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
collapsetrue
package ru.sakhasprintnet.sorm3;

import org.apache.log4j.Logger;
import ru.bitel.bgbilling.common.BGException;
import ru.bitel.bgbilling.kernel.container.managed.ServerContext;
import ru.bitel.bgbilling.kernel.script.server.dev.GlobalScriptBase;
import ru.bitel.bgbilling.modules.inet.api.common.bean.InetSessionLog;
import ru.bitel.bgbilling.modules.inet.api.common.service.InetSessionService;
import ru.bitel.bgbilling.server.util.Setup;
import ru.bitel.common.sql.ConnectionSet;

import java.util.Collections;
import java.util.List;

public class InetSessionStopScript
	extends GlobalScriptBase
{
	private final static Logger logger = Logger.getLogger( InetSessionStopScript.class );

    private final int TEST_CID = -1;

    private final int inetModuleId = 12;

    @Override
    public void execute( Setup setup, ConnectionSet connectionSet )
    throws Exception
    {
        ServerContext serverContext = ServerContext.get();
        InetSessionService sessionService = serverContext.getService( InetSessionService.class, inetModuleId );

        List<InetSessionLog> aliveSessions = getAliveSessions( sessionService );
       	if( aliveSessions != null && aliveSessions.size() > 0 )
       	{
       		logger.info( "Всего сессий для приостановки= " + aliveSessions.size() );
       	}
       	else
       	{
       		logger.info( "Сессий для приостановки не найдено" );
       	}
       	
       	for( InetSessionLog session : aliveSessions )
        {
            try
            {
            	sessionService.connectionFinish( session.getContractId(), session.getConnectionId() );
            }
            catch( BGException e )
            {
                logger.error( "Ошибка при закрытии сессии=" + session.getConnectionId() +
                              " Для договора id=" + session.getContractId() +
                              " Ошибка: " + e.getMessage() );
            }
        }
    }

    private List<InetSessionLog> getAliveSessions( InetSessionService sessionService )
    {
        try
        {
            return sessionService.inetSessionAliveList( null, TEST_CID > 0 ?
                                                            Collections.singleton(TEST_CID) : null ,null,null,null,null,null,null,null ).getList();
        }
        catch( BGException e )
        {
            logger.error( e.getMessage() );
        }

        return Collections.emptyList();
    }
}