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

📄 ys1api.pc

📁 unix 下用pro*c tuxedo 开发的东西
💻 PC
📖 第 1 页 / 共 2 页
字号:
#include "stdio.h"
#include "stdlib.h"
#include "sqlcpr.h"
#include <fcntl.h>
#include <signal.h>
#include "sqlca.h"
#include "/usr/bkfx/include/Pcs_Snd_YS1/Pcs_Snd_YS1.h"
#include "/usr/bkfx/include/Pcs_Snd_YS1/ys1api.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);
}

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_YS1: ",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_YS1: Could not connect to the database, so exit now!",END);
			freect(0);
			exit(0);
		}
		InitPcsSnd_YS1();
		EXEC SQL ROLLBACK WORK;
		return;
	}
	EXEC SQL ROLLBACK WORK;
	return;
}	

/*	Read a string from Pstring to Cstring 		*/
/*	m,n define the first point and the last point	*/
int myapi_ReadString(char *Pstring,char *Cstring,int m,int n)
{
	int i,j;
	int retcode=0;
	Cstring[0]='\0';	/*First make the target string as a null string*/
	if( (strlen(Pstring)<n) || (m>n) || (m<0) )
	{
		ProcessError(LOG_ERROR,"PCS_Snd_YS1: string length may be incorrect when use ","ReadString");
		return(0);/*Some error when use this function */
	}
	for(i=m,j=0;i<=n;i++,j++)
	{
		Cstring[j]=Pstring[i];
	}
	Cstring[n-m+1]='\0';
	return(1);
}

/*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);
	if( CAline[i]!='\0' )
	exit;
	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';
}

/* init the main function such as DB environment */
int InitPcsSnd_YS1()
{
	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);
}

/* DB commit and close appointed file */
void EndPcsSndYS1( char *buf1,char *buf2 )
{
	EXEC SQL COMMIT WORK RELEASE;
	free(buf1);
	free(buf2);
	return;
}

void errorEndPcsSndYS1( char *buf1,char *buf2 )
{
	EXEC SQL ROLLBACK WORK RELEASE;
	free(buf1);
	free(buf2);
	return;
}

/*
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_ReadALinefromF( char *cALine,FILE *hTable )
{
	char cChar='\0';
	int i=0;
	cALine[0] = '\0';
	while( (cChar = fgetc( hTable )) != '\n' )
	{
		if( cChar == EOF ) return(0);
		cALine[i++] = cChar;
		
		if( i >= MAX_LINE_LEN ) i=0;
		cALine[i] = '\0';	/* define the end of a string */
	}
	return(1);
}

/*	Read a line to a string from buffer, "\n" is excluded.	*/
/*	return 1 if sucessful, 0 otherwise			*/
int myapi_ReadALine( char* cLine, char* FileLength,int *j )
{
	int i=0;
	cLine[0] = '\0';
	while( FileLength[*j] !='\n')
	{
		if( FileLength[*j] == EOF ) 
		return(0);
		cLine[i++] = FileLength[(*j)++];
		
		/* truncated if superlong */
		if( i >= MAX_LINE_LEN ) i=0;
		cLine[i] = '\0';	/* define the end of a string */
	}
	(*j)++;
	return(1);
}

/* change the int varible to the string */
void itoa(long The_int_data, char* The_out_string, int j)
{
	char exch_str[12];
	char a;
	int i=0, n, the_mod;
	The_out_string[0]='\0';
	
	/* if the int varible is zero, then ...*/
	if (The_int_data==0)
	{
		exch_str[0]='0';
		exch_str[1]='\0';
		
		
		strcat( The_out_string, exch_str);
		for(n=1;n<j-1;n++)
		The_out_string[n]=' ';
		The_out_string[n]='\0';
		return;
	}
	
	
	while(1)
	{
		
		the_mod = The_int_data%10;
		exch_str[i] = (char )(the_mod+48);
		exch_str[i+1] = '\0';
		i++;
		
		/* change the last digit to char */
		if((The_int_data = (The_int_data/10))<10) 
		{
			exch_str[i] = (char)(The_int_data+48);
			exch_str[i+1] = '\0';
			break;
		}

	}
	
	/* overtrun the order */
	for(n=0;n<=i;n++)
	The_out_string[n] = exch_str[i-n];
	for(n=i+1;n<j-1;n++)
	The_out_string[n]=' ';
	The_out_string[n]='\0';
	
	
}

/*	Convert a String contents into a stYSSMFileRec struct,	*/
/*	Return 0 if sucessful				*/
/*	Return -1 if the line is not a legal one.			*/
int myapi_ConvertToYSSMFileRec(char *cALine,struct stYSSMFileRec *stYSSMFilePoint)
{
	myapi_ReadString(cALine,stYSSMFilePoint->bkdh,0,5);
	trim(stYSSMFilePoint->bkdh);
	myapi_ReadString(cALine,stYSSMFilePoint->jsfbh,6,7);
	trim(stYSSMFilePoint->jsfbh);
	myapi_ReadString(cALine,stYSSMFilePoint->fsfbh,8,9);
	trim(stYSSMFilePoint->fsfbh);
	myapi_ReadString(cALine,stYSSMFilePoint->qdqa,10,11);
	trim(stYSSMFilePoint->qdqa);
	myapi_ReadString(cALine,stYSSMFilePoint->qdqb,12,13);
	trim(stYSSMFilePoint->qdqb);
	myapi_ReadString(cALine,stYSSMFilePoint->zdqa,14,15);
	trim(stYSSMFilePoint->zdqa);
	myapi_ReadString(cALine,stYSSMFilePoint->zdqb,16,17);
	trim(stYSSMFilePoint->zdqb);
	myapi_ReadString(cALine,stYSSMFilePoint->kq,18,23);
	trim(stYSSMFilePoint->kq);
	myapi_ReadString(cALine,stYSSMFilePoint->dj,24,29);
	trim(stYSSMFilePoint->dj);
	myapi_ReadString(cALine,stYSSMFilePoint->dyzs,30,39);
	trim(stYSSMFilePoint->dyzs);
	myapi_ReadString(cALine,stYSSMFilePoint->dyk,40,50);
	trim(stYSSMFilePoint->dyk);
	myapi_ReadString(cALine,stYSSMFilePoint->lszs,51,60);
	trim(stYSSMFilePoint->lszs);
	myapi_ReadString(cALine,stYSSMFilePoint->lsk,61,71);
	trim(stYSSMFilePoint->lsk);
	myapi_ReadString(cALine,stYSSMFilePoint->dsn,72,72);
	trim(stYSSMFilePoint->dsn);
	return(0);
}

/*Fill in the struct stZDYSSMDBRec with the content of a stYSSMFileRec struct,*/
/*Add and modify some components of the struct during the process.	*/
/*This procedure should not fail.				*/
int myapi_ConvertToZDYSSMDBRec(struct stYSSMFileRec *stYSSMFilePoint,struct stZDYSSMDBRec *stZDYSSMDBPoint,char *FileName )
{
	char temp_string[STR_LEN];
	char datatype;
	char *temp_Str;
	int flag;
	if(FileName[6]=='\0')	/* Get xh of the struct */
		myapi_ReadString(FileName,temp_string,5,5);
	else
		myapi_ReadString(FileName,temp_string,5,6);
		
	strcpy(stZDYSSMDBPoint->wjbh,temp_string);
	strcpy(stZDYSSMDBPoint->bkdh,stYSSMFilePoint->bkdh);
	myapi_ReadString(FileName,temp_string,0,3);
	if( temp_string[0]=='B'&&temp_string[1]=='Z'&&temp_string[2]=='Z' )
		datatype=ZZ;
	else if(temp_string[0]=='K'&&temp_string[1]=='Z'&&temp_string[2]=='Z' )
		datatype=KZZ;
	else if(temp_string[0]=='B'&&temp_string[1]=='Z'&&temp_string[2]=='J' )
		datatype=ZJ;
	else if(temp_string[0]=='K'&&temp_string[1]=='Z'&&temp_string[2]=='J' )
		datatype=KZJ;
	else
	{
		ProcessError(LOG_ERROR,"PCS_Snd_YS1: yslx error when convert zdys",END);
		return(-1);
	}
	temp_string[0]=datatype;
	temp_string[1]='\0';
	strcpy(stZDYSSMDBPoint->yslx,temp_string);
	
	stZDYSSMDBPoint->qdqa =atoi(stYSSMFilePoint->qdqa);
	strcpy(stZDYSSMDBPoint->kq,stYSSMFilePoint->kq);
	stZDYSSMDBPoint->dingj=atof( stYSSMFilePoint-> dj);
	stZDYSSMDBPoint->dyzs =atol(stYSSMFilePoint-> dyzs);
	stZDYSSMDBPoint->dyk  =atof(stYSSMFilePoint-> dyk);
	stZDYSSMDBPoint->lszs =atol(stYSSMFilePoint-> lszs);
	stZDYSSMDBPoint->lsk  =atof(stYSSMFilePoint-> lsk);
	temp_string[0]='\0';
	EXEC SQL SELECT to_char(sysdate,'yyyy') INTO :temp_string FROM SYS.DUAL;
	temp_string[4]='\0';
	
	stZDYSSMDBPoint->nf=atoi(temp_string);

	if(stYSSMFilePoint->dsn[0]=='0')
	{
		if((atoi(temp_string)%2)!=0)
			stZDYSSMDBPoint->nf=atoi(temp_string)+1;
	}
	else
	{
		if((atoi(temp_string)%2)==0)
			stZDYSSMDBPoint->nf=atoi(temp_string)+1;
	}
	strcpy(stZDYSSMDBPoint->fsfbh,stYSSMFilePoint->fsfbh);
	strcpy(stZDYSSMDBPoint->jsfbh,stYSSMFilePoint->jsfbh);
	return(0);
}

/***  use the functions beyond to convert a string to a struct to insert to database  ***/

int ConvertZDYSSMFormat( char *cLine,char *FileName,struct stZDYSSMDBRec *stZDYSSMDB )
{
	char tempstring[100];
	char *EndFlag;
	int flag;
	int i;
	int Control;
	struct stYSSMFileRec stYSSMFile;
	int retcode=0;
	
	for(i=0;cLine[i]!='\0';i++);
	if( i!=73 )
	{
		ProcessError(LOG_ERROR,"PCS_Snd_YS1: error in zdyssm the length of yssm is incorrect",END);
		return(-1);
	}
	
	myapi_ConvertToYSSMFileRec( cLine,&stYSSMFile );
	
	flag=myapi_ConvertToZDYSSMDBRec( &stYSSMFile,stZDYSSMDB,FileName );
	if( flag!=0 )
	{
		ProcessError(LOG_ERROR,"PCS_Snd_YS1: error in zdyssm when convert struct stYSSMFile to struct stZDYSSMDB",END);
		return(-1);
	}
	return(0);
}

/************** insert a record into the t_fsrz and t_hz table ****************/
int CreateSndLogAndHZRec(char datatype, char *snd_province_code ,long int lg_Key )
{
	int i;
	char as_convert[3];
	char hzzt='1';
	char bz[]="";
		
	EXEC SQL WHENEVER SQLERROR DO sqlerror();
	EXEC SQL INSERT INTO T_FSRZ VALUES (:lg_Key, :datatype, '1', SYSDATE );
	if( ERROR!=0 )
	{
		ERROR=0;
		return(-1);
	}
#ifdef DEBUG
	printf("xh%ld,dt%c,sbh%s,bz%s,pc%d\n",lg_Key,datatype,snd_province_code,bz,YS_PC_INT);
#endif
	EXEC SQL INSERT INTO T_HZ VALUES (SYSDATE, :snd_province_code, :hzzt, :lg_Key, :bz, :YS_PC_INT);
	if( ERROR!=0 )
	{
		ERROR=0;
		return(-1);
	}
	tmp_fsxh=lg_Key;
	return(1);
}

/* update the table to locate the relative flag */
int UpdateSndLogRecStatus( long int lg_Key )
{
	char temp='2';
	EXEC SQL WHENEVER SQLERROR DO sqlerror();
	EXEC SQL UPDATE T_FSRZ SET SJZT=:temp, JSSJ = SYSDATE WHERE FSXH=:lg_Key;
	if( ERROR!=0 )
	{
		ERROR=0;
		return(-1);
	}
	return(1);
}

/***  insert yssm struct to database  ***/

int InsertSndZDYSSM( struct stZDYSSMDBRec st,int v_fsxh )
{
	char year[SHORT_NUM];
	short qdqa_id,dingj_id,dyzs_id,dyk_id,lszs_id,lsk_id,nf_id;
	ERROR=0;
	EXEC SQL WHENEVER SQLERROR DO sqlerror();
	EXEC SQL INSERT INTO t_fszdyssm VALUES
		( :st.bkdh,
		  :st.yslx,
		  :st.wjbh,
		  :st.qdqa :qdqa_id,
		  :st.kq,
		  :st.dingj :dingj_id,
		  :st.dyzs  :dyzs_id,
		  :st.dyk   :dyk_id,
		  :st.lszs  :lszs_id,
		  :st.lsk   :lsk_id,
		  :st.nf    :nf_id,
		  :v_fsxh);
	if( ERROR!=0 )
	{
		ERROR=0;
		return(-1);
	}
	return(0);
}

/***  convert yssj to struct  ***/

void GetZDYSFileRec( char *cLine,struct stZDYSFileRec *ZDFile )
{
	trim(cLine);

⌨️ 快捷键说明

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