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

📄 myapi.pc

📁 unix 下用pro*c tuxedo 开发的东西
💻 PC
字号:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*	File name		: myapi.pc	                               *
*	Module ID		:				               *
*	Module Name		:                                              *
*	Purpose			: Get GH Data From MQ And Insert into DB       *
*	Author             	: Liu Yan Qiu (DIMPT)                          *
*	Date Created		: 1999,10,27                                   *
*	Version			: Version 1.0                                  *
*	Environment		: HP UNIX                                      *
*	Portability		: UNIX Platform                                *
*	Warnings		:                                              *
*	References		:                                              *
*	Calling Syntax		:                                              *
*	Parameters		: None                                         *
*	Returns			: void                                         *
*	Calling Function	:                                              *
*	Called Functions	: When system startup                          *
*	Datastores and usages	:                                              * 
*        	   (a) Input                                                   *
*	 	   (b) OutPut                                                  *       
*	Report			: None                                         *
*	Screens			: None                                         *
*	Messages Files		: None                                         *
*	Change Log		:                                              *
*	Change No. 	Date	Author	Reason For Change                      *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
*/


#include "/usr/bkfx/include/Cc_Rcv_GH/Cc_Rcv_GH.h"

EXEC SQL INCLUDE SQLCA;

EXEC SQL BEGIN DECLARE SECTION;
     VARCHAR  nr[MAX_LEN_GHNR];
EXEC SQL END DECLARE SECTION;


void Free_Mem()
{
 	if ( buf_hz != NULL) free( buf_hz );
 	if ( tmp != NULL ) free( tmp );
 	if ( data_type != NULL ) free( data_type );
 	if ( QXMsg != NULL ) free( QXMsg );
 	CloseErrLogObj();
 	MQBKClear();
 	EXEC SQL RollBack RELEASE;
}


int ReadGHMsg()  
{
	
	if ( ((buf = (char *)malloc( LEN_GH_BUF+1 ))==NULL) || \
	     ((data_type = (char *)malloc( LEN_DATA_TYPE ))==NULL))
        {
        	ProcessError(LOG_ERROR,"Malloc GH Buffer Error!");
        	CloseErrLogObj();
 		MQBKClear();
		exit(-1);
	}

	tmp = buf;
	
	rtn_code = MQBKReceiveSyn_Wait(&buf_length, buf, data_type );
	if ( rtn_code < 0 ) 
	{	
		free( data_type );
		free( tmp );
		return(-2);
	}
        else
        {	
        	
                
                if ( (( data_type[0] == 'G' ) && ( data_type[1] == 'H' )) || \
                     (( data_type[0] == 'J' ) && ( data_type[1] == 'H' ))  ||   \
                     (( data_type[0] == 'B' ) && ( data_type[1] == 'T' )) )
                {
 
 			strncpy( c_fsxh ,buf, 10);
 			c_fsxh[10]='\0';
 			fsxh = atoi( c_fsxh);
 			buf = buf + 10;
 
 			strncpy( fssjbh, buf, 2);
 			fssjbh[2]='\0';
 			buf = buf + 2;
 
 			strncpy( jssjbh, buf, 2);
 			jssjbh[2]='\0';
 			buf = buf + 2;
 
 			strncpy( ghbh, buf, 3);
 			ghbh[3]='\0';
 			buf = buf + 3;
 
 			strncpy( ghxl, buf, 2);
 			ghxl[2]='\0';
 			buf = buf + 2;
 
 			strcpy( nr.arr, buf);
 			nr.len = strlen( nr.arr);
 			
 			#ifdef DEBUG
				printf("Cc_Rcv_GH.x : Rece a GH file, jsxh is %d\n",fsxh);
 				printf("Cc_Rcv_GH.x : the fssjbh, jssjbh, ghbh, ghxl is: %s, %s, %s, %s\n",fssjbh, jssjbh, ghbh, ghxl);
 			#endif
 			
 			free( tmp );

 		}
 		
 		else if ( ( data_type[0] == 'C' ) && ( data_type[1] == 'A' ) && \
                     	( data_type[2] == 'N' ))  /* when data_type is CANCEL */
                {
                
                	strncpy( c_fsxh, buf, 10);
 			c_fsxh[10]='\0';       
 			fsxh = atoi( c_fsxh);
 			buf = buf+10;
 
 			strncpy( fssjbh, buf, 2);
 			fssjbh[2]='\0';
 			buf = buf + 2;
 
 			strncpy( jssjbh,buf,2);
 			jssjbh[2]='\0';
 			buf = buf + 2;
			
			#ifdef DEBUG
 				printf("Cc_Rcv_GH.x : Recv a Cancel Msg, jsxh is %d\n",fsxh);
 				printf("Cc_Rcv_GH.x : the fssjbh, jssjbh is : %s, %s\n",fssjbh, jssjbh);
			#endif
			
		/*  *tmp will be used in funntion Cancel_UpdateJSRZAndZFRZ(), \
			so it can't be free now */
 		}
		else 
		{
       			free( tmp );
       			free( data_type );
			return(-3);
		}
	}
	
 	return(1);      
}


int CreateGHRcvLogStatus()
{
 	char sjbh_99[3];
 	int i=1, sj_count;
 
 	EXEC SQL INCLUDE SQLCA;
 	EXEC SQL WHENEVER SQLERROR GOTO sqlerror;

     	if  ( (( jssjbh[0] == '0') && ( jssjbh[1] == '0' )) ||  \
              (( jssjbh[0] == '9') && ( jssjbh[1] == '9' )) )
        	
        EXEC SQL INSERT INTO T_JSRZ 
             VALUES( :fsxh, '5', '1', :fssjbh, sysdate );
        
	printf("insert t_jsrz ok!");

     	if ( strcmp( jssjbh, "00" ) != 0 ) 
        { 
          	EXEC SQL INSERT INTO t_zfrz
               		VALUES (:fsxh, '5', '1', sysdate, :fssjbh );

          	printf("insert t_zfrz ok!");

          	if (( jssjbh[0] == '9' ) && ( jssjbh[1] == '9' ))
             	{
               	               
			EXEC SQL SELECT count(*) INTO :sj_count FROM T_SJBH 
				WHERE SJBH<>'99' AND SJBH<>:fssjbh ;
		

			EXEC SQL DECLARE sjbh_cursor CURSOR FOR
         				SELECT SJBH FROM T_SJBH 
					WHERE SJBH<>'99' AND SJBH<>:fssjbh ;

			EXEC SQL OPEN sjbh_cursor;	

   			for (i=1; i <= sj_count; i++) 
			{
			
			EXEC SQL FETCH sjbh_cursor INTO :sjbh_99;

			#ifdef DEBUG
				printf("jssjbh is %s\n",sjbh_99);
			#endif
	     		
       			EXEC SQL INSERT INTO t_zfdz 
                            	VALUES ('1', :fsxh, :sjbh_99, :fssjbh);

			}
			EXEC SQL CLOSE sjbh_cursor;
		
             	}
          	else
             	{ 
                	EXEC SQL INSERT INTO t_zfdz
                     		VALUES ('1', :fsxh, :jssjbh, :fssjbh );
			printf("insert t_zfdz ok!");
            	} 
        }   
            

   	EXEC SQL COMMIT;
   	return(1);
     
	sqlerror:
   	ProcessError(LOG_ERROR,"Running Function CreateRcvLogStatus() \
   				SQL Error!");
   	free( data_type );
   	EXEC SQL ROLLBACK;
   	return (-1);
}


int InsertRcvGHRec()
{
 
    	EXEC SQL WHENEVER SQLERROR GOTO sqlerror;

    	if ( (( jssjbh[0] == '0') && ( jssjbh[1] == '0' )) ||  \
             (( jssjbh[0] == '9') && ( jssjbh[1] == '9' )) )
        {

          	EXEC SQL INSERT INTO t_jsgh
               		VALUES( :ghbh, :ghxl, :nr, :fsxh, :fssjbh );  
              printf("insert t_jsgh ok!");

        	rtn_code = SndHZMsg();
          	if ( rtn_code < 0 ) 
          	{
          		free( data_type );
          		return(-1);
          	}

        }
         
     	if ( strcmp( jssjbh, "00" ) != 0 ) 
        {
          	EXEC SQL INSERT INTO t_zfgh
               		VALUES( :ghbh, :ghxl, :nr, :fsxh, :fssjbh );
		printf("insert t_zfgh ok!");

        }
               
    	EXEC SQL COMMIT;
    	return(1);

	sqlerror:
   	ProcessError(LOG_ERROR,"Running Function InsertRcvGHRec() SQL Error!");
   	free( data_type );
   	EXEC SQL ROLLBACK;
   	return (-1);
}




int SndHZMsg()
{

 	if ( (buf_hz = (char *) malloc (LEN_HZ)) == NULL )
 	{
        	ProcessError(LOG_ERROR,"Malloc HZ Buffer Error!");
		return(-1);
	}
 	memset( buf_hz, '\0', LEN_HZ);

 	strncat( buf_hz, c_fsxh, 11);
 	strncat( buf_hz, fssjbh, 3);
 	buf_hz[12]='0';
 	buf_hz[13]='0';
 	buf_hz[14]='\0';
 	
 	#ifdef DEBUG
		printf("Cc_Rcv_GH.x : the hz msg is %s\n",buf_hz);
	#endif
	
        rtn_code = MQBKSend_Syn( strlen(buf_hz), buf_hz, atoi(fssjbh), "HZ");
        if ( rtn_code <0 ) 
        {
        	ProcessError(LOG_ERROR,"Sendding HZ Message Error!");
        	free(buf_hz);
        	return(-1);
        }
        
	rtn_code = MQBKCmit();
        if ( rtn_code < 0 )
        {
        	ProcessError(LOG_ERROR,"Commit HZ Message Error!");
                free(buf_hz);
                MQBKBack();
                return(-1);
        }

 	free(buf_hz);
 	return(1);
 	
}



int UpdateGHRcvLogStatus()
{
  	EXEC SQL WHENEVER SQLERROR GOTO sqlerror;

  	if  ( (( jssjbh[0] == '0') && ( jssjbh[1] == '0' )) ||  \
              (( jssjbh[0] == '9') && ( jssjbh[1] == '9' )) )
  
     		EXEC SQL UPDATE t_jsrz SET sjzt='2' WHERE jsxh=:fsxh;

  /*	else
     	{
     	
      		EXEC SQL UPDATE t_zfdz SET zfzt='2' WHERE zfxh=:fsxh;

      		EXEC SQL UPDATE t_zfrz SET sjzt='2' WHERE zfxh=:fsxh;

     	}
*/

	if  ( strcmp( jssjbh, "00" ) != 0 ) 
       {
       
  		EXEC SQL UPDATE t_zfdz SET zfzt='2' WHERE zfxh=:fsxh;

      		EXEC SQL UPDATE t_zfrz SET sjzt='2' WHERE zfxh=:fsxh;

	}

  	EXEC SQL COMMIT;
  	return(1);

	sqlerror:
   	ProcessError(LOG_ERROR,"Running Function UpdateRcvLogStatus() \
   				SQL Error!");
   	free( data_type );
   	EXEC SQL ROLLBACK;
   	return (-1);
}


int Cancel_UpdateJSRZAndZFRZ()
{

   	EXEC SQL WHENEVER SQLERROR GOTO sqlerror;

   	if ( (( jssjbh[0] == '0') && ( jssjbh[1] == '0')) || \
   	      ( jssjbh[0] == '9') )
   	{
     		EXEC SQL UPDATE T_JSRZ SET sjzt = '5' , jssj = sysdate
              		WHERE jsxh = :fsxh AND sjbh = :fssjbh;
   	}
   
     	if ( strcmp( jssjbh, "00" ) != 0 ) 
    	{
     		EXEC SQL UPDATE T_ZFRZ SET sjzt = '5' , jssj = sysdate
              		WHERE zfxh = :fsxh AND sjbh = :fssjbh;
        }
    
   	EXEC SQL COMMIT;
   
   	return(1);
 
	sqlerror:
   	ProcessError(LOG_ERROR, "Running Function Cancel_UpdateJSRZAndZFRZ() \
   					SQL Error!");
   	free( tmp );
   	EXEC SQL ROLLBACK;
   	return(-1);          
   	
}



int Cancel_UpdateZFDZAndSendMQ()
{
   	int 	count_zfdz,i;
   

   	EXEC SQL WHENEVER SQLERROR GOTO sqlerror;
   
     	if ( strcmp( jssjbh, "00" ) != 0 )   
       	{
       		
     		if ( strcmp( jssjbh, "99" ) != 0 )  /* when cancel_msg send to another PCS */
             	{
                  	rtn_code = MQBKSend_Syn(strlen(tmp),tmp,atoi(jssjbh),"CANCEL");
                  	if (rtn_code <0)  
              		{
              			ProcessError(LOG_ERROR,"Sendding Cancel Message Error!" );
              			free( tmp );
				free( data_type );
				MQBKBack();
              			return(-1);
              		}
              		
   			rtn_code = MQBKCmit();
              		if ( rtn_code < 0 ) 
	       	      	{
	       	      		
	       	      		ProcessError(LOG_ERROR,"Commit Cancel Message Error!");
	       	      		free( tmp );
				free( data_type );
				MQBKBack();
              			return(-1);
       	      		}

             	}
        	else  /* when cancel_msg send to all PCS */
             	{
             		if ( (QXMsg = ( char *)malloc (LEN_QXMsg)) == NULL )
             		{
        			ProcessError(LOG_ERROR,"Malloc Cancel Message Buffer Error!");
        			free( tmp );
				free( data_type );
				return(-1);
			}
			
               		EXEC SQL SELECT count(*) INTO :count_zfdz
                		FROM t_zfdz
                		WHERE zfxh = :fsxh AND fsfsjbh = :fssjbh; 
 
       			EXEC SQL DECLARE qx_c CURSOR FOR
               			SELECT jsfsjbh FROM t_zfdz
               			WHERE zfxh = :fsxh AND fsfsjbh = :fssjbh; 
                    
       			EXEC SQL OPEN qx_c;
               
       			for (i=1; i<= count_zfdz; i++)
                	{
                  		EXEC SQL FETCH qx_c INTO :jssjbh;
                  		
                  		memset( QXMsg, '\0', LEN_QXMsg);
                  		
                  		strcpy( QXMsg, c_fsxh);
                  		strcat( QXMsg, fssjbh);
                  		strcat( QXMsg, jssjbh);
                 
               			rtn_code = MQBKSend_Syn(strlen(QXMsg),QXMsg,atoi(jssjbh),"CANCEL");
               			if (rtn_code <0)  
              			{
              				ProcessError(LOG_ERROR,"Sendding Cancel Message Error!");\
              			 	free( tmp );
					free( data_type );
					free( QXMsg );
					return(-1);	
              
              			}
              			
              			#ifdef DEBUG
       					printf("the qxmsg and send code is %s%d\n", \
       							QXMsg,rtn_code);
       				#endif
       			}
       			
                 	EXEC SQL CLOSE qx_c;

		        rtn_code = MQBKCmit();
		        if ( rtn_code < 0 ) 
	       	      	{
	       	      		
	       	      		ProcessError(LOG_ERROR,"Commit Cancel Message Error !");
				free( tmp );
				free( data_type );
				free( QXMsg );
				return(-1);
              			
              		}
               	 	
                 	free( QXMsg );
       		}	/* end of else */


     		EXEC SQL UPDATE T_ZFDZ SET zfzt = '5' WHERE zfxh = :fsxh;             
        }
        
	free( tmp );
   	return(1);
 
	sqlerror:
   		ProcessError(LOG_ERROR, "Running Function Cancel_UpdateZFDZAndSendMQ() Error!");
   		free( tmp );
   		free( data_type );
   		free( QXMsg );
   		EXEC SQL ROLLBACK;
   		return(-1);          
}


/*Get the Time_Interval specified in the file and return it */
int GetTimeInterval(char* cType)
{
	FILE *hTimeInterval;
	char cLine[MAX_LINE_LEN+1], cCaption[100], cValue[21];
	int iInterval, i;
	char* pLine;
	
	 
	hTimeInterval = fopen( CONFIG_FILE_FOR_TIMEINTERVAL, "r" );
	if( hTimeInterval == NULL )
	{
		ProcessError(LOG_ERROR,   "GetTimeInterval: this is %s message: \
		Cannot open file: %s,The file may not exist!", \
		"ERROR", CONFIG_FILE_FOR_TIMEINTERVAL);
		return(DEFAULT_TIMEINTERVAL);  
	}
	
	while( myapi_ReadALine( cLine, hTimeInterval ) )
	{
		if( cLine[0] == '#' ) continue;
		if( cLine[0] == NULL ) continue;
		
		pLine = cLine;
		while( (*pLine == ' ') || (*pLine == '\t') ) pLine++;
		i=0;
		while( (*pLine != ' ') && (*pLine != '\t') && (*pLine != '\0') )
		{
			cCaption[i] = *pLine;
			i++;
			pLine++;
		}
		
		cCaption[i] = '\0';
		if( strcmp( cCaption, cType ) == 0 ) /*Match*/
		{
			while( (*pLine == ' ') || (*pLine == '\t') ) pLine++;
			if( *pLine == '\0' )
				return(DEFAULT_TIMEINTERVAL);
			i=0;
			while( (*pLine != ' ') && (*pLine != '\t') && (*pLine != '\0') )
			{
				cValue[i] = *pLine;
				i++;
				pLine++;
			}
			cValue[i] = '\0';
			iInterval = atoi(cValue);
			
			if(iInterval <= 0) 		
			{
				return(DEFAULT_TIMEINTERVAL);
			}
			else
				return(iInterval);
		}
		else
			continue;
	}
	fclose( hTimeInterval );
	return(DEFAULT_TIMEINTERVAL);
}

/*Read a line to a string from a file, \n is excluded.
  return 1 if sucessful, 0 otherwise
  Do not close the file.*/
int myapi_ReadALine( char* cLine, FILE* hTable )
{
	char cChar;
	int i=0;
	cLine[0] = '\0';
	while( (cChar = fgetc( hTable )) != '\n' )
	{
		if( cChar == EOF ) return(0);
		cLine[i++] = cChar;
		
		
		if( i >= MAX_LINE_LEN ) i=0;
		cLine[i] = '\0';
	}
	return(1);
}

⌨️ 快捷键说明

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