⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 signonservice.java

📁 银行项目为后台socket通信写的程序
💻 JAVA
字号:
/****************************************************************************
 * Package		: com.ecSolutions.ecAppServer.business
 * File			: SignOnService.java
 * Create Date  : 2007-7-21
 * Author		: Steven Chen
 * 
 * Copyright(C) 2006 ecSolutions(shanghai) Co.,Limited.All Rights Reserved.
 *			
 ***************************************************************************/
package com.ecSolutions.ecAppServer.business;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

import org.apache.log4j.Logger;

import com.ecSolutions.ecAppServer.Configuration;
import com.ecSolutions.ecAppServer.appSession.AppServerSessionMgr;
import com.ecSolutions.ecAppServer.appSession.DuplicateSessionException;
import com.ecSolutions.ecAppServer.appSession.ExecFunctionFailException;
import com.ecSolutions.ecAppServer.appSession.LoginResponse;
import com.ecSolutions.ecAppServer.appSession.User;
import com.ecSolutions.ecAppServer.appSession.UserLoginFailException;
import com.ecSolutions.ecAppServer.config.PropertiesConfiguration;
import com.ecSolutions.ecAppServer.util.DbUtil;
import com.ecSolutions.ecAppServer.util.FileUtil;

public class SignOnService extends Thread {
	private String req;

	private AppServerSessionMgr sessionMgr;

	private static Logger log = Logger.getLogger("SignOnService");

	public SignOnService(String request) {
		this.req = request;
	}

	public LoginResponse signOn() throws UserLoginFailException {

		/*
		 * try {
		 *  } catch (UserLoginFailException e) { log.error(e.toString());
		 * LoginResponse loginResponse = new
		 * LoginResponse("0060",e.getMessage(),""); //call send message
		 * 
		 * 
		 * return; }
		 */
		// DbUtil du = new DbUtil("oracle", "direct");
		Connection conn = null;
		try {
			conn = DbUtil.getConnection();
		} catch (SQLException e2) {
			log.error("error in create connection " + e2);
			throw new UserLoginFailException("error in create connection");
		}
		String sessionID = "";
		try {
			String menu = "";
			// 1.检查用户合法性
			User user = new User(req);

			Configuration config = PropertiesConfiguration.getInstance();

			if (config.getString("USERWRK").equals("Y")) {
				if (user.checkUserExists(conn)) {
					// user has login, client is difference
					throw new UserLoginFailException(
							"User already login at other place");
				}
			}
			if (config.getString("WRKSESS").equals("Y")) {
				if (user.checkClientMachineExists(conn)) {
					// client has been used
					throw new UserLoginFailException(
							"Not allow multiply sessions on the same workstation");
				}
			}

			if (user.checkUserLocked(conn)) {
				throw new UserLoginFailException("User is locked");
			}

			menu = user.userLogin(conn);

			// 2.生成session
			conn.setAutoCommit(false);
			user.createUserSession(conn);
			sessionID = user.getSessionId();

			sessionMgr = AppServerSessionMgr.getInstance();
			try {
				sessionMgr.store(sessionID, user);
			} catch (DuplicateSessionException e) {				
				log.error("Session is  Duplicate"+e);
				throw new UserLoginFailException("EA01621");
			}

			// 3.生成工作站记录
			user.createWorkStationRecord(conn);
			
			// 4.创建用户工作区
			Date d = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
			String dt = sdf.format(d);
			user.setcurrentdate(dt);
			user.createUserWorkArea(sessionID);

			// set responese

			LoginResponse loginResponse = new LoginResponse("0156", "HSUC",
					sessionID, user.getPort(), menu,
					user.getLocalMachineName(), dt);
			user.updateT57(conn);
			user.insertToT60(conn, "1");
			conn.commit();
			return loginResponse;
		} catch (Exception e) {
			try {
				if (conn != null && !conn.isClosed())
					conn.rollback();
				conn.setAutoCommit(true);
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			if(!sessionID.equals("")){
			sessionMgr.removeSession(sessionID);
			}
			log.error("error in login" + e);
			if(e instanceof UserLoginFailException){
				throw new UserLoginFailException(e.getMessage());
			}
			throw new UserLoginFailException("EA01621");
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e) {
				}
				conn = null;
			}
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -