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

📄 dbsmgw.cpp

📁 电信的97接口程序,用于把话单入库。这里是采用FTP方式采集话单
💻 CPP
📖 第 1 页 / 共 5 页
字号:
}

int CInterfaceContent::GetUserGroup(char* userGroup)
{
	RTRACE(6, "Step into CInterfaceContent::GetUserGroup");
	char sql[SQL_SIZE];
	strcpy(sql, "select * from ACCGroupType where AccountsType = '");
	strcat(sql, userGroup);
	strcat(sql, "'");
	// Run sql
	RTRACE(3, sql);
	dbclrbuf(m_dbproc, sizeof(sql));
	dbcmd(m_dbproc, sql);
	if (dbsqlexec(m_dbproc) != SUCCEED )
	{
		RTRACE(3, "Record ACCGroupType record fail");
		while ( (m_retRow = dbnextrow(m_dbproc)) != NO_MORE_ROWS )
			if ( m_retRow == FAIL )
				break;
		dbcancel(m_dbproc);
		return -1;
	}
	dbresults(m_dbproc);	
	if (dbnextrow(m_dbproc) != NO_MORE_ROWS)
	{
		return 0;
	}
	else
	{
		RTRACE(5, "NO_MORE_ROWS for UserGroup");
		return -1;
	}

	return 0;
}

int CInterfaceContent::GetDateDiff(char* userAccounts)
{
	RTRACE(6, "Step into CInterfaceContent::GetDateDiff");

	if(CGlobal::Instance()->m_rollback < 0)
		return -1;
	
	char sql[SQL_SIZE];
	strcpy(sql, "select datediff(dd, ModifyTime, getdate()) from UserAcct where UserAccounts = '");
	strcat(sql, userAccounts);
	strcat(sql, "'");
	// Run sql
	RTRACE(3, sql);
	dbclrbuf(m_dbproc, sizeof(sql));
	dbcmd(m_dbproc, sql);
	if (dbsqlexec(m_dbproc) != SUCCEED )
	{
		RTRACE(3, "Record ACCGroupType record fail");
		while ( (m_retRow = dbnextrow(m_dbproc)) != NO_MORE_ROWS )
			if ( m_retRow == FAIL )
				break;
		dbcancel(m_dbproc);
		return -3; // Exec sql error 
	}
	dbresults(m_dbproc);
	DBINT dbDateDiff;
	int dateDiff;
	dbbind(m_dbproc, 1, INTBIND, (DBINT) 0, (BYTE *)&dbDateDiff);
	if (dbnextrow(m_dbproc) != NO_MORE_ROWS)
	{
		dateDiff = (int)dbDateDiff;
		// rollback = 0 means can rollback anytime
		if(dateDiff <= CGlobal::Instance()->m_rollback || 
			CGlobal::Instance()->m_rollback == 0) 
			return 0;
		else
			return -1; // can not rollback. Time is too old
	}
	else
	{
		RTRACE(5, "NO_MORE_ROWS for UserGroup");
		return -2; // can not find record to fit the condition. Can not rollback either.
	}
}

int CInterfaceContent::GetInheritType(char *userAccounts)
{
	char sql[SQL_SIZE];
	m_inheritGroup = 0; //not inherit
	if(strcmp(m_aCLICP, "") == 0  && strcmp(m_aCLContent, "") == 0 && m_sendRecv == 0)
		m_inheritGroup = 1;

	strcpy(sql, "select UseGroup, UserStatus, UserType from UserAcct where UserAccounts = '");
	strcat(sql, userAccounts);
	strcat(sql, "'");
	// Run sql
	RTRACE(3, sql);
	dbcmd(m_dbproc, sql);

	if (dbsqlexec(m_dbproc) != SUCCEED )
	{
		RTRACE(3, "Record UserAcct record fail");
		while ( (m_retRow = dbnextrow(m_dbproc)) != NO_MORE_ROWS )
			if ( m_retRow == FAIL )
				break;
		dbcancel(m_dbproc);
		return (-1);
	}

	dbresults(m_dbproc);
	DBINT inheritGroup;
	DBINT userStatus;
	unsigned char oldUserType[2];

	dbbind(m_dbproc, 1, INTBIND, (DBINT) 0, (BYTE *)&inheritGroup);
	dbbind(m_dbproc, 2, INTBIND, (DBINT) 0, (BYTE *)&userStatus);
	dbbind(m_dbproc, 3, STRINGBIND, (DBINT) 0, oldUserType);

	if (dbnextrow(m_dbproc) != NO_MORE_ROWS)
	{
		m_inheritGroup = (int)inheritGroup;
		m_userStatus = (int)userStatus;
		strncpy(m_oldUserType, (char *)oldUserType, 2);
	}
	else
	{
		RTRACE(5, "NO_MORE_ROWS " << m_inheritGroup);
		return -1;
	}

	return 0;	
}

int CInterfaceContent::GetAdsiAttr(char *userAccounts)
{
	RTRACE(6, "Enter interface GetAdsiAttr");
	char sql[SQL_SIZE];
	strcpy(sql, "select 1 from AdsiAttr where UserAccounts = '");
	strcat(sql, userAccounts);
	strcat(sql, "'");
	RTRACE(5, sql);

	dbcmd(m_dbproc, sql);
	if (dbsqlexec(m_dbproc) != SUCCEED )
	{
		RTRACE(3, "Record UserAcct record fail");
		dbcancel(m_dbproc);
		return (-1);
	}

	dbresults(m_dbproc);
	if (dbnextrow(m_dbproc) != NO_MORE_ROWS)
	{
		RTRACE(5, "MORE_ROWS");
		return 0;
	}
	else
	{
		RTRACE(5, "NO_MORE_ROWS ");
		return -1;
	}
}

int CInterfaceContent::OperateDb()
{
	char newTel[41];
	char oldTel[41];
	sprintf(newTel, "%s%s", m_areaNo, m_teleNumber);
	sprintf(oldTel, "%s%s", m_areaNo, m_oldTeleNum);
	newTel[40] = '\0';
	oldTel[40] = '\0';

	/*if(m_operateType/10 == 1) // the operation of rollback
	{
		if(GetDateDiff(newTel) < 0)
			return -9; // can not rollback operation. Bacause time expire.
	}*/

	switch(m_operateType)
	{
	case 0: //开户
		{
			RTRACE(3, "begin the Operation Inserting user");

            if ( CheckGrpList(m_groupList) != 0 )
            {
                return -14;
            }

			GetUserStatusFromTable(newTel); // get the status of users
			if(m_userStatus == 3 || m_userStatus == 2) // can be deleted or pause
			{
				// Judge if you can delete the telephone number
				if(DeleteRecord(newTel) == 0)
				{
					GetDeleteSQL();
					ExecSQL(m_sql, m_sql2);
					LinkDelete(newTel); // delete the linking account
					ExecSQL(m_sql, "");
					LinkedDelete(newTel); // delete the linked account
					ExecSQL(m_sql, "");
				}
				else
				{
					RTRACE(2, "Warning! Insert sql error!");
					RTRACE(2, "\t" << newTel<< " exists and can't be deleted!");
					return -7;
				}
			}
			else if (m_userStatus != 0)
			{
				RTRACE(2, "Warning! Insert sql error!");
				RTRACE(2, "\t" << newTel<< " exists!");
				return -7;
			}
			GetInsertSQL();
			break;
		}
	case 1: //消户
		{
			RTRACE(3, "begin the Operation deleting user");
			if(GetUserStatusFromTable(newTel) < 0)
				return -10;
			else if(m_userStatus == 3)
				return -11;
			if(CGlobal::Instance()->m_deleteNow == 1)
				GetDeleteSQL();
			else
			{
				SetUserStatus(3);
				m_sql2[0] = '\0';
			}
			ExecSQL(m_sql, m_sql2);
			LinkedDelete(newTel);
			break;
		}

	case 2: //变更
		{
			// Judging the exist the oldTelNum.
			// if not exists, it only modifed the properties of UserAcct
			// if exists, it the change number of the users.
			RTRACE(3, "begin the Operation updating user");

          // modified by btrmg for jiangsu sockets 2005.03.01
            if ( CheckGrpList(m_groupList) != 0 )
			{
				return -14;
			}
			
          
			memset(m_oldUserType, 0, sizeof(m_oldUserType));

			int newInherit = GetInheritType(newTel);
			int newStatus = m_userStatus;
			int oldInherit = GetInheritType(oldTel);
			int oldStatus = m_userStatus;

			// old telephone number does not exist or old has been deleted
			if(oldInherit == -1  || oldStatus == 3) 
			{

				// old not exists, and new not exists too.
				if(newInherit == -1) // Can't find the record or sql execute error
				{
					RTRACE(3, "Error! Old not exist and new not too!");
					m_sql[0] = '\0';
					m_sql2[0] = '\0';
					return -4;
					//GetInsertSQL();
				}
				else if(newStatus == 3)
				{
					/*
					if(DeleteRecord(newTel) == 0)
					{
						GetDeleteSQL();
						ExecSQL(m_sql, m_sql2);
						GetInsertSQL();
					}
					else
					{
						RTRACE(2, "Warning! Update sql error!");
						RTRACE(2, "\t" << newTel<< " exists and can't be deleted!");
						return -1;
					}
					*/
					RTRACE(3, "Error! Old not exist and new not too!");
					m_sql[0] = '\0';
					m_sql2[0] = '\0';
					return -4;
				}
				// old not exists, but new exists.
				else
					GetUpdateSQL();
			}
			else 
			{
				// old exists, but new not exists
				if(strcmp(m_userType, m_oldUserType) != 0)
				{
					RTRACE(2, "Error! Can't change the user type!");
					return -13;
				}

				if(newInherit == -1) // Can't find the record or sql execute error
				{

					SetUserStatus(2, m_areaNo, m_oldTeleNum);
					ExecSQL(m_sql, "");
					LinkDelete(oldTel);
					ExecSQL(m_sql, "");
					LinkInsert(oldTel, newTel);
					ExecSQL(m_sql, "");
					LinkChange(oldTel, newTel);
					GetInsertSQL();

//					RTRACE(3, "Error! Old exists, but new not exist!");
//					return -4;
				}
				// old exists, but new's status is deleted
				else if(newStatus == 3)
				{
					if(DeleteRecord(newTel) == 0)
					{
						GetDeleteSQL();
						ExecSQL(m_sql, m_sql2);
						SetUserStatus(2, m_areaNo, m_oldTeleNum);
						ExecSQL(m_sql, "");
						LinkDelete(oldTel);
						ExecSQL(m_sql, "");
						LinkInsert(oldTel, newTel);
						ExecSQL(m_sql, "");
						LinkChange(oldTel, newTel);
						GetInsertSQL();
					}
					else
					{
						RTRACE(2, "Warning! Update sql error!");
						RTRACE(2, "\t" << newTel<< " exists and can't be deleted!");
						return -1;
					}
				}
				
				// old exists, and new exists too.
				// if old telephone number equal to new's, then the operation is
				// change properties. 
				// if old telephone number is not equal to new's. The error.
				else
				{
					if(strcmp(newTel, oldTel) == 0)
						GetUpdateSQL();
					else
					{
						RTRACE(2, "Warning !");
						RTRACE(2, "\tWant to change number from " << oldTel << " to " << newTel);
						RTRACE(2, "\tBut " << newTel << " exists, and " << oldTel << " exists too.");
						m_sql[0] = '\0';
						m_sql2[0] = '\0';
						return -5;
					}
				}
			}
			break; 
		}

	case 333: //停机, 3是否要做产品类型变更?
		{
			RTRACE(3, "begin the Operation pause user");
			if(GetUserStatusFromTable(newTel) < 0)
				return -10;
			else if(m_userStatus != 1)
				return -11;
			SetUserStatus(2);
			break;
		}

	case 444: //恢复, JS has no 4 type
		{
			RTRACE(3, "begin the Operation resume user");
			if(GetUserStatusFromTable(newTel) < 0)
				return -10;
			else if(m_userStatus != 2)
				return -11;
			SetUserStatus(1);
			break;
		}
    case 5: //帐户绑定,江苏97 add by zjl 2002-10-30
        {
            RTRACE(3, "begin to bind account");

            if ( CheckGrpList(m_groupList) != 0 )
            {
                return -11;
            }

			if (GetUserStatusFromTable(oldTel) == -1) // get the status of users
            {
                RTRACE(2, "Bind account, but bill account dose not exist");
                return -91;
            }
			if(m_userStatus != 1) // bill account status is not normal
			{
			    RTRACE(2, "Bind account, but bill account'userStaus != 1");
                return -92;
			}
            if (GetUserStatusFromTable(newTel) == 0)
            {
                if (m_userStatus == 1 || m_userStatus == 2)
                {
                    RTRACE(2, "Bind account, but bind account is already exist");
                    return -93;
                }
                else
                {
				    if(DeleteRecord(newTel) == 0)
				    {
					    GetDeleteSQL();
					    ExecSQL(m_sql, m_sql2);
					    LinkDelete(newTel); // delete the linking account
					    ExecSQL(m_sql, "");
				    }
				    else
				    {
                        RTRACE(2, "Bind account, but bind account is already exist");
                        return -93;
				    }
                }
            }
            LinkInsert(newTel, oldTel);
            ExecSQL(m_sql, "");
			GetInsertSQL(1); //IsLink = 1
            break;
        }
    case 6: //帐户绑定解除,江苏97 add by zjl 2002-10-30
        {
            RTRACE(3, "begin to Unbind account");

            if (GetUserStatusFromTable(newTel) == -1)
            {
                RTRACE(2, "UnBind account, but bind account dose not exist");
                return -94;
            }

		    LinkDelete(newTel); // delete the linking account
			ExecSQL(m_sql, "");

            SetUserStatus(3);
            break;
        }

    case 10: //增加股神通业务
        {
            RTRACE(3, "begin add group list to one user");
            if ( CheckGrpList(m_groupList) != 0 )
            {
                return -11;
            }

            GetUserStatusFromTable(newTel);
            if ( m_userStatus == 0 )
            {
                RTRACE(2, "newTel " << newTel 
                    << " dose not exits, can't add GST power!" );
                return -12;
            }
            else if ( m_userStatus != 1 )
            {
                RTRACE(2, "newTel " << newTel 
                    << " was paused, can't add GST power!" );
                return -13;
            }            

            return AddGroupList(newTel);
        }
    case 11: //去除股神通业务
        {
            RTRACE(2, "begin remove group list from one user");

            if ( CheckGrpList(m_groupList) != 0 )
            {
                return -11;
            }

            GetUserStatusFromTable(newTel);
            if ( m_userStatus == 0 )
            {

⌨️ 快捷键说明

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