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

📄 yxpapi.pc

📁 unix 下用pro*c tuxedo 开发的东西
💻 PC
字号:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
EXEC SQL INCLUDE SQLCA; 
#include <fcntl.h>
#include <signal.h>
#include "/usr/bkfx/include/myapi.h"
#include "/usr/bkfx/include/Pcs_Snd_YX_P/Pcs_Snd_YX_P.h"
#include "/usr/bkfx/include/Pcs_Snd_YX_P/cmYXStr.h"
#include "/usr/bkfx/include/Pcs_Snd_YX_P/cmdef.h"

void ProcessError( char *LOG, char *sErrorMessage1, char *sErrorMessage2 )
{
	FILE* hErrorFile;
	char cDateTime[100],tempstr[100];
	int i,j,len,n;
	long filesize;
	char bakfile[100];
	
	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;
		}
			
	}
	
	printf("\n%s",LOG);
	printf("%s",sErrorMessage1);
	printf("%s",sErrorMessage2);
	printf("%s\n",tempstr);

	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 );
	filesize = ftell(hErrorFile);
	if (filesize > 5242880/5)
	{
		fclose(hErrorFile );
		sprintf(bakfile, "mv %s %s.bak", ERROR_LOG_FILE, ERROR_LOG_FILE);
		system(bakfile);
		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);
	fputs( sErrorMessage1,hErrorFile );
	fputs( sErrorMessage2,hErrorFile );
	fputs( tempstr,hErrorFile );
	fputs( "\n",hErrorFile);
	fclose( hErrorFile );

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

void PutintoF(char *string )
{
	FILE *fp;
	fp=fopen("checkfile.txt","w");
	fputs(string,fp);
	fclose(fp);
}

int UpdateSndLogStatus(long serial_no,
                       char status)
{
   
    EXEC SQL WHENEVER SQLERROR DO sqlerror();     /*  SQL error handling */
    EXEC SQL UPDATE t_fsrz  SET sjzt = :status  
                       WHERE fsxh = :serial_no;
    return(0);
}

int UpdateHZStatus(long serial_no,char *rcv_province_code,
                       char status)
{
    EXEC SQL WHENEVER SQLERROR DO sqlerror();     /*  SQL error handling */
    EXEC SQL UPDATE t_hz  SET hzzt = :status, hzjssj = SYSDATE
                          WHERE fsxh = :serial_no AND sjbh = :rcv_province_code;
    return(0);
}

void sqlerror()
{
	char tempstring[200];
	char ERR_CODE[10];
	int init_time=0;
	
	ERROR=1;
	EXEC SQL WHENEVER sqlerror continue;
	ProcessError( LOG_ERROR, "PCS_SND_YXP: ",sqlca.sqlerrm.sqlerrmc );
	strncpy(ERR_CODE,sqlca.sqlerrm.sqlerrmc,9);
	ERR_CODE[9]='\0';
	if( strcmp(ERR_CODE,"ORA-03127")==0|| strcmp(ERR_CODE,"ORA-03114")==0|| strcmp(ERR_CODE,"ORA-03123")==0|| strcmp(ERR_CODE,"ORA-01034")==0|| strcmp(ERR_CODE,"ORA-01089")==0||strcmp(ERR_CODE,"ORA-01012")==0||strcmp(ERR_CODE,"ORA-01089") ==0||strcmp( ERR_CODE, "ORA-01033") ==0 )
	{
		sleep(INIT_INTERVAL);
		init_time++;
		if (init_time == 6)
		{
			ProcessError(LOG_NORMAL, "PCS_SND_YXP: Could not connect to the database, so exit now!",END);
			freect(0);
			exit(0);
		}
		InitPcsSndYXP();
		EXEC SQL ROLLBACK WORK;
		return;
	}
	EXEC SQL ROLLBACK WORK;
	return;
}	

/*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 message:Cannot open file", 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' )
			{
				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);
}


int InitPcsSndYXP()
{
    	int rtncode;
	EXEC SQL BEGIN DECLARE SECTION;
	VARCHAR username[20];
	VARCHAR password[20];
	EXEC SQL END DECLARE SECTION;
	
	strcpy(username.arr,"pcsdba");
	username.len=strlen(username.arr);
	strcpy(password.arr,"dba");
	password.len=strlen(password.arr);
	EXEC SQL WHENEVER SQLERROR DO sqlerror();
	EXEC SQL CONNECT :username IDENTIFIED BY :password;
	if( ERROR!=0 )
	{
		ERROR=0;
		return(-1);
	}
	return(0);
}

/*delete the ' ' or '\n' of a string at the begin and end*/

void trim(char *CAline)
{
	int i,j;
	char temp_string[100];
	i=strlen(CAline);
	while(i>0)		/*delete the end ' ' or '\n' */
	{
		if(CAline[i-1]==' '||CAline[i-1]=='\n')
			CAline[i-1]='\0';
		else
			break;
		i--;
	}
	i=0;j=0;
	while( CAline[i]!='\0' )	/*delete the head ' ' or '\n' */
	{
		if(CAline[i]==' '||CAline[i]=='\n')
			i++;
		else
		{
			for (j=0;CAline[i]!='\0';i++,j++)
				CAline[j]=CAline[i];
			break;	
		}	
	}
	CAline[j]='\0';
}


/* add '0' at head of string converted from num */

int strformat(char *tempstr)
{
	int    old,new,count;
	char  test_str[MID_LEN],tempstring[MID_LEN];
	strcpy(test_str,tempstr);
	trim(test_str);
	old=strlen(tempstr);
	new=strlen(test_str);
	count=old-new;
	tempstring[0]='\0';
	for( ;count>0;count-- )
		strcat(tempstring,"0");
	strcat(tempstring,test_str);
	strcpy(tempstr,tempstring);
	return(0);
}

int EndPcsSndYXP()
{
    	EXEC SQL COMMIT WORK RELEASE;       
    	return(0);
}    

int getMsgHeader(char *jssbh, long int serial_no)
{
    	mheader[0] = '\0'; 
    	EXEC SQL VAR fi_no IS STRING;
    	EXEC SQL VAR subtype IS STRING;
    	EXEC SQL WHENEVER NOT FOUND DO sqlerror();
    	EXEC SQL SELECT wjbh,yxxl INTO :fi_no,:subtype FROM t_fsyxsj
         	WHERE fsxh = :serial_no;
    	if( ERROR!=0 )
    	{
    		ERROR=0;
   		ProcessError(LOG_ERROR,"PCS_Snd_YX_P: not found when retrieve from t_fsyxsj ",END);
  		return(-1);
    	}

 /*   	itoa(serial_no,rec_YX_Msg.fsxh,11);*/
/*	sprintf(rec_YX_Msg.fsxh,"%10ld",serial_no);
    	strcpy(mheader,rec_YX_Msg.fsxh);
    	strcat(mheader,snd_city);
    	strcat(mheader,jssbh);
    	strcat(mheader,fi_no);
   	strcat(mheader,subtype);	*/
	sprintf(mheader,"%10ld%2s%2s%2s%3s",serial_no,snd_city,jssbh,fi_no,subtype);
    	return(0);

}
 
int sleep_please()
{  
    	sleep_time=GetTimeInterval("PCS_SND_YX_P");
    	sleep(sleep_time);
    	return(0);
}

int PcsSndYX2(long serial_no,long len_msg)
{    
   
    	char gid_string[4]; 
    	int  i=0,gid,flag,center; 
    	char rcv_province_code[3];
    	int  con_round,ctrl;
    	int  total_zh;
    	char total_zh_string[10];
 	char lastflag;
	
EXEC SQL BEGIN DECLARE SECTION;
     VARCHAR tmpdata[LEN_YX_REC+1];
EXEC SQL END DECLARE SECTION;

	center=0;

    	EXEC SQL DECLARE cur_zh CURSOR FOR 
         	SELECT zh,zzh,zcfssj FROM t_zcfssj 
         	WHERE fsxh = :serial_no ORDER BY zh; 
  
	/*  Read and send each record of YX record   */ 
    	EXEC SQL OPEN cur_zh;
    	while (1)
    	{
        	EXEC SQL WHENEVER NOT FOUND DO break;
        	EXEC SQL FETCH cur_zh INTO :gid,:total_zh,:tmpdata;
		if( gid-total_zh>0 )
            	if( flag!=0 )
            	{
            		EXEC SQL CLOSE cur_zh;
           		ProcessError(LOG_ERROR,"PCS_Snd_YX_P: error when found zh > zzh",END);
          		return(-1);
            	}
			
	    
            	/*  Organize YX message header: fsxh+fssbh+wjbh+yxxl  */
            	strcpy(rcv_province_code,"00");
            	flag=getMsgHeader(rcv_province_code,serial_no);
            	if( flag!=0 )
            	{
            		EXEC SQL CLOSE cur_zh;
           		ProcessError(LOG_ERROR,"PCS_Snd_YX_P: error when getmsgheader",END);
          		return(-1);
            	}
            	sprintf(mheader,"%s%3d%3d%s",mheader,gid,total_zh,tmpdata.arr);
		mheader[25+tmpdata.len]='\0';
#ifdef	DEBUG
		PutintoF(mheader);
		printf("msglen is %d  %d\n",strlen(mheader),tmpdata.len);
#endif

            	/****send mheader string to mq****/
		if(MQBKSend_Syn(strlen(mheader) ,mheader, center,"YX") < 0)
		{
			MQBKBack();
			EXEC SQL ROLLBACK WORK;
			ProcessError(LOG_ERROR,"Pcs_Snd_YX_P: error when send msg to mq",END);
			return(-1);
		}
		if( gid-total_zh==0 )	
		{
			flag=MQBKCmit();
			if( flag<0 )
			{
				ProcessError(LOG_ERROR,"Pcs_Snd_YX_P: error when mqbkcmit",END);
				MQBKBack();
				EXEC SQL ROLLBACK WORK;
				return(-1);
			}
#ifdef DEBUG
	printf("this is the last group\n");
#endif
		

  	          	/*  Update T_HZ status to SENDED    */ 
            		status = HZ_SENDED;
            		UpdateHZStatus(serial_no,rcv_province_code,status);
	    		break;
        	} 
    	} 


    	EXEC SQL CLOSE cur_zh;
    	return(0);
}

⌨️ 快捷键说明

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