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

📄 myapi.pc

📁 unix 下用pro*c tuxedo 开发的东西
💻 PC
字号:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

*	File name		: myapi.pc			    		*				

*	Module ID		: MD-P17-04			    		*

*	Module Name		: 			    			*

*	Purpose			: Sub Function Used By Pcs_Snd_ZFJB_P.pc	*

*	Author          	: Liu Yan Qiu (DIMPT)		    		*

*	Date Created		: 1999/10/21			    		*

*	Version			: Version 1.0			    		*

*	Environment		: Digital Unix			    		*

*	Portability		: DEC ALPHA Server			    	*

*	Warnings		:                 			    	*

*	References		:                 			    	*

*	Calling Syntax		:                 			    	*

*	Parameters		: None            			    	*		

*	Returns			: void             			    	*

*	Calling Function	:                 			    	*

*	Called Functions	:                 			    	*

*	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/Pcs_Snd_ZFJB_P/Pcs_Snd_ZFJB_P.h"





void Free_Mem()

{ 

	ProcessError(LOG_NORMAL, "Pcs_Snd_ZFJB_P.x Is Terminated By User!",END);

 	if ( buf_msg != NULL ) free( buf_msg );

	MQBKClear();

	EXEC SQL RollBack RELEASE;

	exit(0);

}





int InitSndZFJBP()

{  



 	EXEC SQL BEGIN DECLARE SECTION;

      		VARCHAR  userid[20];

      		VARCHAR  password[20];

 	EXEC SQL END DECLARE SECTION; 



 

 	/*********************************

   	|   Get Process waiting interval |

   	**********************************/

 	

 	interval = GetTimeInterval("PCS_SND_ZFJB_P");





 	/*****************************

  	| Connect to DataBase	     |

  	*****************************/

  

 	strcpy( userid.arr, "pcsdba" );

	userid.len = strlen( userid.arr );

	strcpy( password.arr, "dba" );

	password.len = strlen( password.arr );

	

	

 	EXEC SQL WHENEVER SQLERROR GOTO sqlerror;

 	EXEC SQL CONNECT :userid IDENTIFIED BY :password;



  	      

 	return(1);

 

 	sqlerror:

	EXEC SQL WHENEVER SQLERROR CONTINUE;

	ProcessError(LOG_ERROR,   "DataBase Error:%s!", sqlca.sqlerrm.sqlerrmc );

 	exit(-1);

 	

}





int PCSSndZFJBP()

{  

	int 	count_rec;

	long	key;

	int	n,i;

	

   	EXEC SQL WHENEVER SQLERROR GOTO sqlerror;



   while (1)

   {

	

   	EXEC SQL SELECT count(*) INTO :count_rec FROM T_FSRZ 

        		WHERE sjfl = '4' AND sjzt = '2';

	

	if ( count_rec == 0 )  sleep( interval ); 

  	else

	{

           	EXEC SQL DECLARE zfj_cursor CURSOR FOR

                    	SELECT FSXH 

                    	FROM T_FSRZ

                    	WHERE sjfl = '4' AND sjzt = '2';

   		

           	EXEC SQL OPEN zfj_cursor;

      

           	for (i=1; i<=count_rec; i++)

           	{

              

               		EXEC SQL FETCH zfj_cursor INTO :key;

               		

                	rtn_code = PCSSndZFJBP2(key);

                	if (rtn_code < 0)

                	{

                  		ProcessError(LOG_ERROR,"Pcs_Snd_ZFJB_P.x: Calling \

                  					Function PCSSndZFJBP2() Failed!",END);

                  		continue;

                 	}

                	

           		rtn_code = MQBKSend_Syn(strlen(buf_msg), buf_msg, 00, "ZFJ");

			free( buf_msg );

			if (rtn_code <0)  

              		{

              			ProcessError(LOG_ERROR,"Pcs_Snd_ZFJB_P.x: Sendding \

              						ZFJB Message Error!",END);

          			MQBKBack();

	               		continue;

              		}

              	

			rtn_code = MQBKCmit();

              		if ( rtn_code < 0 ) 

	       		{

       	      			ProcessError(LOG_ERROR,"Pcs_Snd_ZFJB_P.x: Commit \

       	      						ZFJB Message Error!",END);

    	      			MQBKBack();

               	  		continue;

			}

	       	      	

	       	      	

	       	      	EXEC SQL UPDATE T_FSRZ SET sjzt='3' WHERE FSXH = :key;

               

      			EXEC SQL UPDATE T_HZ SET hzzt='2' WHERE FSXH = :key;      			    			

      			

       	      	}	/* end of for */

     		EXEC SQL COMMIT;  

  		EXEC SQL CLOSE zfj_cursor;

  		

		sleep( interval );

  	}	/* end of else */



   } 	/* end of while */

    

    	return(1);



    	sqlerror:

	EXEC SQL WHENEVER SQLERROR CONTINUE;

	ProcessError(LOG_ERROR,   "DataBase Error:%s!", sqlca.sqlerrm.sqlerrmc );

   	ProcessError(LOG_ERROR,"Pcs_Snd_ZFJB_P.x: Running Function PCSSndZFJBP() \

   				Error!",END);

   	if ( buf_msg != NULL ) free( buf_msg );

 	EXEC SQL RollBack;

   	return(-1);

}







int PCSSndZFJBP2(long fsxh)

{

 	int	count_zfj, i;

 	int	len_buf_msg;

 	long	year_l;

 	char	year_s[5], key_s[11], jssjbh[3], fssjbh[3], zfjbh[9], zfjmc[17];



	EXEC SQL WHENEVER NOT FOUND GOTO sqlerror;	



 

 	EXEC SQL SELECT nf INTO :year_l FROM T_FSZFJB

          	WHERE FSXH = :fsxh;

          

 	EXEC SQL SELECT count(*) INTO :count_zfj 

          	FROM T_FSZFJBNR 

          	WHERE FSXH = :fsxh; 

          

 	len_buf_msg = LEN_FSXH + LEN_JSSJBH + LEN_FSSJBH + LEN_NF +  \

 			count_zfj*( LEN_MsgRec_ZFJB ) + 1; 

 

	while(1)

	{



		if ( (buf_msg = (char *) malloc (len_buf_msg))==NULL )

 		{

			ProcessError(LOG_ERROR,"Pcs_Snd_ZFJB_P.x: Malloc ZFJB Buffer \

 					Error!",END);

			sleep(InitInterval);

		}

		else

			break;



 	}



 	memset(buf_msg, '\0', len_buf_msg);



 	EXEC SQL SELECT bsbh into :fssjbh FROM t_bsbh;

        fssjbh[2] = '\0';

  

	sprintf( key_s,"%d",fsxh );

	for ( i = strlen(key_s); i<LEN_FSXH; i++ )

	key_s[i] = ' ';

	key_s[i] = '\0';

	

 	sprintf( year_s, "%d", year_l);

	year_s[4] = '\0';

  	

	strcpy(jssjbh,JSSJBH);

	jssjbh[2] = '\0';



   	strcat(buf_msg, key_s);

   	strcat(buf_msg, fssjbh);

   	strcat(buf_msg, jssjbh);      	

   	strcat(buf_msg, year_s);



	#ifdef DEBUG

		printf("fsxh, nf, fssjbh, jssjbh is: \

			%s, %s, %s, %s\n",key_s,year_s,fssjbh,jssjbh);

	#endif

	

 	EXEC SQL DECLARE zfjb_cursor CURSOR FOR

          	SELECT  zfjbh, zfjmc

       		FROM T_FSZFJBNR

      		WHERE FSXH = :fsxh

			ORDER BY zfjxh;  /* by Mr. zjk 2000.05.11 */

 	EXEC SQL OPEN zfjb_cursor;



 	for (i=1; i<=count_zfj; i++)

     	{ 

      		EXEC SQL FETCH zfjb_cursor INTO :zfjbh, :zfjmc;  

   

      		zfjbh[8] = '\0';

      		zfjmc[16] = '\0';



      		strcat(buf_msg, zfjbh);

      		strcat(buf_msg, zfjmc);



      		

      		#ifdef DEBUG

      			printf("zfjbh and zfjmc and zfjxh is %s %s\n", zfjbh,zfjmc);

      		#endif

     	}



      	EXEC SQL CLOSE zfjb_cursor; 



 	return(1);     		 

 	sqlerror:

	EXEC SQL WHENEVER SQLERROR CONTINUE;

	ProcessError(LOG_ERROR,   "DataBase Error:%s!", sqlca.sqlerrm.sqlerrmc );

 	ProcessError(LOG_ERROR,"Pcs_Snd_ZFJB_P.x: Running Function PCSSndZFJBP2() \

 				SQL Error!",END);

	if ( buf_msg != NULL ) free( buf_msg );

	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!",END);

		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' )

			{	fclose( hTimeInterval );

				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) 		

			{

				fclose( hTimeInterval );

				return(DEFAULT_TIMEINTERVAL);

			}

			else

				fclose( hTimeInterval );

				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);

}



void ProcessError( char *LOG, char *sErrorMessage1, char *sErrorMessage2 )

{

	FILE* hErrorFile;

	char cDateTime[100],tempstr[100];

	int i,j,len,n;

	

	tempstr[0]='\0';

	len=strlen(sErrorMessage1);

	for(i=0;i<=len;i++)

	{

		if(sErrorMessage1[i]=='%')

		{			

			n=i;

			if(len!=i+1)

			{

				for(j=0;j<200&&sErrorMessage1[i+2]!='\0';j++,i++)

				tempstr[j]=sErrorMessage1[i+2];

				tempstr[j]='\0';

			}	

			break;

		}

		if(sErrorMessage1[i]=='\0')

		{

			n=i;

			tempstr[0] = '\0';

			break;

		}

			

	}

	

	

	sErrorMessage1[n]='\0';

	hErrorFile = fopen( ERROR_LOG_FILE, "a" );

	if( hErrorFile == NULL )

	{

		printf( "Critical! Cannot open ERROR_LOG_FILE for append or cannot create!\n");

		return;

	}

	fseek( hErrorFile, 0 ,SEEK_END );

	fputs( "\n",hErrorFile);

	fputs( LOG ,hErrorFile);

	printf("\n%s",LOG);

	fputs( sErrorMessage1,hErrorFile );

	printf("%s",sErrorMessage1);

	fputs( sErrorMessage2,hErrorFile );

	printf("%s",sErrorMessage2);

	fputs( tempstr,hErrorFile );

	printf("%s\n",tempstr);

	fputs( "\n",hErrorFile);

	fclose( hErrorFile );

	sprintf( cDateTime, "date >> %s\n", ERROR_LOG_FILE );

	system( cDateTime );

}



⌨️ 快捷键说明

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