Ejemplo n.º 1
0
int F930067(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg)
{
	int ret = 0;
	int cnt=0;
	int msgid=0;
	char sysdatetime[21]="";
       T_t_msglist tMsgList;
	T_t_device tDevice;

	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);
	ResetNormalCPack(&aPack,0,1);

	memset(&tMsgList,0,sizeof(tMsgList));
	memset(&tDevice,0,sizeof tDevice);
	
	if(strlen(in_pack->sdate0)==0)
	{
		if(in_pack->lcert_code <= 0)
		{
			*pRetCode=E_DEVPHYID_NULL;
			goto L_RETU;
		}
		tMsgList.deviceid = in_pack->lcert_code;
	}
	else
	{
		if((ret = get_devinfo_by_phyid(in_pack->sdate0,&tDevice)))
		{
			*pRetCode = ret;
			goto L_RETU;
		}
		tMsgList.deviceid = tDevice.deviceid;
	}
	
	des2src(sysdatetime,CAccTrans::getInstance()->trans.sysdatetime);
	AddXmlItemInt(tMsgList.reqdata,XML_KEY_FTFLAG,in_pack->lvol3);	

	tMsgList.funcno = 930067;
	tMsgList.msglevel = 2;
	ret=AddMsgLst(&tMsgList);
	if(ret)
	{
		*pRetCode=ret;
		writelog(LOG_ERR,"AddMsgLst err[%d]",ret);
		goto L_RETU;
	}	
	if(iRequest!=tMsgList.funcno)
		return 0;	
	ret=db_commit();
	if(ret)
	{
		writelog(LOG_ERR,"db_commit ret[%d]",ret);
		*pRetCode=E_DB_COMMIT;
		goto  L_RETU;
	}
	msgid=tMsgList.msgid;
	for(cnt=0;(cnt<10)&&(tMsgList.errcode!=0);cnt++)
	{
		sleep(1);
		memset(&tMsgList,0,sizeof(tMsgList));
		ret=DB_t_msglist_read_by_msgid(msgid, &tMsgList);
		if(ret)
		{
			writelog(LOG_ERR,"DB_t_msglist_read_by_msgid err[%d]",ret);
			*pRetCode=E_DB_MSGLIST_R;
			goto L_RETU;
		}
	}
	switch(tMsgList.errcode)
	{
		case 0:		//成功
			des2src(out_pack->vsvarstr0,"成功");
			break;
		case 9999:		//交易未处理
			des2src(out_pack->vsvarstr0,"前置机无应答");
			break;
		default:			//交易已经处理,但结果是失败
			des2src(out_pack->vsvarstr0,tMsgList.errmsg);				
			break;
	}	
	SetCol(handle,0);
	SetCol(handle,F_VSVARSTR0,0);
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return  -1;	
}
Ejemplo n.º 2
0
int F240007(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	char path_name[256]="";
	char file_name[256]="";
	int ret=0;
	int cnt=0;
	int i=0;

	T_t_tif_bank_comp	bank_comp;				// 银行对账文件数据存储表
	T_t_tif_report_trans_comp trans_comp;		// 财务统计报表
	T_t_tif_tradeserial	tradeserial;			// 当前流水表
	T_t_tif_tradeserial_his his_tradeserial;	// 历史流水表	
	T_t_tif_diff_transfer  diff_transfer;		// 银行对账文件和流水文件对账差异表

	char logicdate[10]="";
	char tmp_date[10]="";
	char forward_date[10]="";					// 结算时间从文件名中取得

	double trans_count=0;
	double bank_count=0;
	double trans_amt=0;
	double bank_amt=0;
	double second=0;

	double temp=0;
	memcpy(forward_date, rPack->scard1 + 6, 8);		// BANK + 银行标识(04) + 日期 + txt
	writelog(LOG_ERR,"bank compare name=[%s]", rPack->scard1);

	memset(&bank_comp,0,sizeof(bank_comp));
	memset(&trans_comp,0,sizeof(trans_comp));
	memset(&tradeserial,0,sizeof(tradeserial));
	memset(&his_tradeserial,0,sizeof(his_tradeserial));

	ret=DB_t_tif_report_trans_comp_read_by_cmp_date(forward_date,&trans_comp);
	if(ret!=100&&ret!=0)
	{
		writelog(LOG_ERR,"DB_t_tif_report_trans_comp_read_by_cmp_date error,errcode=[%d]",ret);
		goto LRet;
	}
	if(1==trans_comp.cmp_flag)
	{
		writelog(LOG_ERR,"trans_comp.cmp_flag =1,already compare!");
		goto LRet;
	}

	memset(&bank_comp,0,sizeof(bank_comp));
	des2src(bank_comp.bankcard, rPack->scust_auth);		// 银行卡号
	des2src(bank_comp.bank_sn, rPack->scust_auth2);		// 银行端流水号
	bank_comp.card_id = atoi(rPack->sorder0);			// 校园卡交易卡号
	bank_comp.local_sn = atoi(rPack->semp_no);			// 校园卡流水号		
	des2src(bank_comp.op_date, forward_date);			// 对账的交易时间
	des2src(bank_comp.trans_money, rPack->sorder1);		// 转帐金额
	des2src(bank_comp.tx_code, rPack->scust_type);		// 交易代码
	writelog(LOG_ERR, "bank_card=[%20.20s], bank_sn=[%20.20s], card_id=[%d], local_sn=[%d], date=[%8.8s], trade_code=[%2.2s], trans_money=[%9.9s]", bank_comp.bankcard, bank_comp.bank_sn, bank_comp.card_id, bank_comp.local_sn, bank_comp.op_date, bank_comp.tx_code, bank_comp.trans_money);
	
	// 文件读完标识, 如果文件已经读完了, 则开始进行对账, 0表示还需读取记录, 1表示没有记录可读
	if (0 == rPack->lvol0)
	{
		ret = DB_t_tif_bank_comp_add(&bank_comp);
		if (ret)
		{
			writelog(LOG_ERR,"DB_t_tif_bank_comp_add rows[%d] error,errcode=[%d]",cnt,ret);
			goto LRet;
		}

		ret = db_commit();
		if (ret)
		{
			writelog(LOG_ERR,"db_commit error,errcode=[%d]",ret);
			goto LRet;
		}

		goto L_RETU;
	}
	
	//开始进行对帐
	cnt=0;

	// 对一卡通转帐总数
	ret=DB_his_t_tif_tradeserial_get_count_by_serial_type(&temp,240001,forward_date);
	if(ret!=100&&ret!=0)
	{
		writelog(LOG_ERR,"DB_t_tif_tradeserial_get_count_by_serial_type err,errcode=[%d]",ret);
		goto LRet;
	}
	trans_count=trans_count+temp;
	trans_comp.localself_num=trans_count;

	// 对一卡通转帐总金额
	ret=DB_his_t_tif_tradeserial_get_sum_by_serial_type(&temp, 240001, forward_date);
	if(ret!=100&&ret!=0)
	{
		writelog(LOG_ERR,"DB_his_t_tif_tradeserial_get_sum_by_serial_type err,errcode=[%d]",ret);
		goto LRet;
	}
	trans_amt=trans_amt+temp;
	trans_comp.localself_amt=trans_amt;

	ret=DB_t_tif_bank_comp_open_select_by_cur1_and_op_date(forward_date);
	if(ret)
	{
		writelog(LOG_ERR,"DB_t_tif_bank_comp_open_select_by_cur1_and_op_date err,errcode=[%d]",ret);
		goto LRet;
	}
	while(1)
	{
		ret=DB_t_tif_bank_comp_fetch_select_by_cur1(&bank_comp);
		if(ret)
		{
			DB_t_tif_bank_comp_close_select_by_cur1();
			if(ret==DB_NOTFOUND)
			{
				if(cnt==0)
				{
					writelog(LOG_DEBUG,"There havn't record from t_tif_bankcomp table!");
					break;
				}
				else		
					break;
			}
			else
				goto LRet;
		}

		cnt++;
		bank_count=bank_count+1;
		bank_amt=bank_amt+atof(bank_comp.trans_money)/100.00;
		memset(&diff_transfer,0,sizeof(diff_transfer));

		// 以银行端的存储的一卡通流水号到一卡通流水表中查询数据
		ret=DB_t_tif_tradeserial_his_read_by_bak_date_and_serial_no(forward_date,bank_comp.local_sn,&his_tradeserial);
		if(ret)
		{
			if(100==ret)
			{
				// 一卡通中不存在的流水, 银行端存在的流水, 记入对账差异表中
				strncpy(diff_transfer.op_date,forward_date,sizeof(diff_transfer.op_date)-1);
				strncpy(diff_transfer.bankcard,bank_comp.bankcard,sizeof(diff_transfer.bankcard)-1);
				diff_transfer.bank_amt=atoi(bank_comp.trans_money)/100.00;
				strncpy(diff_transfer.bank_sn,bank_comp.bank_sn,sizeof(diff_transfer.bank_sn)-1);
				diff_transfer.card_id=bank_comp.card_id;
				diff_transfer.local_sn=bank_comp.local_sn;
				diff_transfer.diff_amt=diff_transfer.bank_amt-diff_transfer.local_amt;
				diff_transfer.status=1;
				ret=DB_t_tif_diff_transfer_add(&diff_transfer);
				if(ret)
				{
					writelog(LOG_ERR,"DB_t_tif_diff_transfer_add error,errcode=[%d]!",ret);
					break;
				}
				continue;
			}
			else
			{
				writelog(LOG_ERR,"DB_t_tif_tradeserial_his_read_lock_by_c0_and_enteract_date_and_serial_no error,errcode=[%d]!",ret);
				break;
			}
		}
		if(his_tradeserial.serial_state!=2)
		{
			// 一卡通中存在的流水, 发起未入账, 银行端对此流水已经入账, 记入对账差异表中	
			strncpy(diff_transfer.op_date,forward_date,sizeof(diff_transfer.op_date)-1);
			strncpy(diff_transfer.bankcard,bank_comp.bankcard,sizeof(diff_transfer.bankcard)-1);
			diff_transfer.bank_amt=atoi(bank_comp.trans_money)/100.00;
			strncpy(diff_transfer.bank_sn,bank_comp.bank_sn,sizeof(diff_transfer.bank_sn)-1);
			diff_transfer.card_id=bank_comp.card_id;
			diff_transfer.local_amt=0;
			diff_transfer.local_sn=bank_comp.local_sn;
			diff_transfer.diff_amt=diff_transfer.bank_amt-diff_transfer.local_amt;
			diff_transfer.status=1;
			ret=DB_t_tif_diff_transfer_add(&diff_transfer);
			if(ret)
			{
				writelog(LOG_ERR,"DB_t_tif_diff_transfer_add error,errcode=[%d]!",ret);
				break;
			}
		}
	}

	trans_comp.bankself_amt=bank_amt;
	trans_comp.bankself_num=bank_count;
	trans_comp.localself_amt=trans_amt;
	trans_comp.localself_num=trans_count;
	trans_comp.cmp_flag=1;
	strncpy(trans_comp.cmp_date,forward_date,sizeof(trans_comp.cmp_date)-1);
	ret=DB_t_tif_report_trans_comp_add(&trans_comp);
	if(ret)
	{
		writelog(LOG_DEBUG,"DB_t_tif_report_trans_comp_add error,errcode=[%d]",ret);
		goto LRet;

	}

	ret=db_commit();
	if(ret)
	{
		writelog(LOG_ERR,"db_commit error,errcode=[%d]",ret);
		goto LRet;
	}
	return 0;

LRet:
	db_rollback();
	return ret;

L_RETU:
	return ret;
}
Ejemplo n.º 3
0
int F930002(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg)
{
	int ret = 0;
	int cnt=0;
	int msgid=0;
       T_t_msglist tMsgList;
//	T_t_device tDevice;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);
	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LSERIAL1,F_SDATE0,F_SSERIAL0,F_VSVARSTR0,0);

	memset(&tMsgList,0,sizeof(tMsgList));
//	memset(&tDevice,0,sizeof tDevice);

	tMsgList.deviceid = in_pack->lcert_code;
	if(!tMsgList.deviceid)
	{
		return E_INPUTNULL_DEVICE;
	}	
	tMsgList.funcno = 930002;
	tMsgList.msglevel = MESLIST_PRIORITY_REALTIME;
	ret=AddMsgLst(&tMsgList);
	if(ret)
	{
		*pRetCode=ret;		
		writelog(LOG_ERR,"AddMsgLst err[%d]",ret);
		goto L_RETU;
	}
	if(iRequest!=tMsgList.funcno)
		return 0;	
	ret=db_commit();
	if(ret)
	{
		writelog(LOG_ERR,"db_commit ret[%d]",ret);
		*pRetCode=E_DB_COMMIT;
		goto  L_RETU;
	}
	msgid=tMsgList.msgid;
	des2src(out_pack->sdate0,in_pack->sdate0);
	for(cnt=0;(cnt<20)&&(tMsgList.errcode!=0);cnt++)
	{
		sleep(1);
		memset(&tMsgList,0,sizeof(tMsgList));
		ret=DB_t_msglist_read_by_msgid(msgid, &tMsgList);
		if(ret)
		{
			writelog(LOG_ERR,"DB_t_msglist_read_by_msgid err[%d]",ret);
			*pRetCode=E_DB_MSGLIST_R;
			goto L_RETU;
		}
	}
	switch(tMsgList.errcode)
	{
		case 0:		//成功
			ret=GetXmlValue(out_pack->sserial0,sizeof(out_pack->sserial0),XML_KEY_CLOCK, tMsgList.respdata);
			if(ret)
			{
				*pRetCode=ret;
				goto L_RETU;
			}
			des2src(out_pack->vsvarstr0,"成功");
			break;
		case 9999:		//交易未处理
			des2src(out_pack->vsvarstr0,"前置机无应答");
			break;
		default:			//交易已经处理,但结果是失败
			des2src(out_pack->vsvarstr0,tMsgList.errmsg);				
			break;
	}	
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return  -1;	
}
Ejemplo n.º 4
0
int F930002(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg)
{
	int ret = 0;
	int cnt=0;
	int mesid=0;
       T_t_tif_meslist tMesList;
	T_t_device tDevice;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);
	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LSERIAL1,F_SDATE0,F_SSERIAL0,F_VSVARSTR0,0);

	memset(&tMesList,0,sizeof(tMesList));
	memset(&tDevice,0,sizeof tDevice);

	if(strlen(in_pack->sdate0)==0)
	{
		if(in_pack->lcert_code <=0 )
		{
			*pRetCode=E_DEVPHYID_NULL;
			goto L_RETU;
		}
		tMesList.devid = in_pack->lcert_code;
	}
	else
	{
		if((ret = get_devinfo_by_phyid(in_pack->sdate0,&tDevice)))
		{
			*pRetCode = ret;
			goto L_RETU;
		}
		tMesList.devid = tDevice.deviceid;
	}
	
	tMesList.funid = 930002;
	tMesList.level = MESLIST_PRIORITY_REALTIME;
	ret=AddMsgLst(&tMesList);
	if(ret)
	{
		*pRetCode=ret;		
		writelog(LOG_ERR,"AddMsgLst err[%d]",ret);
		goto L_RETU;
	}
	if(iRequest!=tMesList.funid)
		return 0;	
	ret=db_commit();
	if(ret)
	{
		writelog(LOG_ERR,"db_commit ret[%d]",ret);
		*pRetCode=E_DB_COMMIT;
		goto  L_RETU;
	}
	mesid=tMesList.mesid;
	des2src(out_pack->sdate0,in_pack->sdate0);
	for(cnt=0;(cnt<10)&&(tMesList.ecode!=0);cnt++)
	{
		sleep(1);
		memset(&tMesList,0,sizeof(tMesList));
		ret=DB_t_tif_meslist_read_by_mesid(mesid, &tMesList);
		if(ret)
		{
			writelog(LOG_ERR,"DB_t_tif_meslist_read_by_mesid err[%d]",ret);
			*pRetCode=E_DB_MESLIST_R;
			goto L_RETU;
		}
	}
	switch(tMesList.ecode)
	{
		case 0:		//成功
			ret=GetXmlValue(out_pack->sserial0,sizeof(out_pack->sserial0),XML_KEY_CLOCK, tMesList.outcontent);
			if(ret)
			{
				*pRetCode=ret;
				goto L_RETU;
			}
			des2src(out_pack->vsvarstr0,"成功");
			break;
		case 9999:		//交易未处理
			des2src(out_pack->vsvarstr0,"前置机无应答");
			break;
		default:			//交易已经处理,但结果是失败
			des2src(out_pack->vsvarstr0,tMesList.emsg);				
			break;
	}	
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return  -1;	
}
Ejemplo n.º 5
0
int F841607(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	int i=0;
	int iCnt=0;
	int flag=0;
	T_t_cif_phototmp tPhotoTmp;
	T_t_cif_phototmp tPhotoTmpOut;
	T_t_cif_photo  tYktPhoto;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

	memset(&tPhotoTmp,0,sizeof(T_t_cif_phototmp));
	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_SCUST_LIMIT,F_VSMESS,0);

	tPhotoTmp.seqno=rPack->lvol4;
	if(1==tPhotoTmp.seqno)
	{
		flag=1;
		//取批次号
		getsysdatetime(tPhotoTmp.batch_no);
		ret=DynamicStmtExecute("delete from ykt_cur.t_cif_phototmp");
		if(ret)
		{
			if(DB_NOTFOUND != ret)
			{
				*pRetCode=E_DYNAMIC_STMT_EXECUTE;
				goto L_RETU;
			}
		}
	}
	else
	{
		des2src(tPhotoTmp.batch_no,rPack->scust_limit);
		if(strlen(tPhotoTmp.batch_no)!=14)
		{
			*pRetCode=E_INPUT_BATCH_NO;
			goto L_RETU;
		}
	}
	des2src(tPhotoTmp.stuemp_no,rPack->scust_auth);
	des2src(tPhotoTmp.stuemp_name,rPack->sname);
	des2src(tPhotoTmp.cut_type,rPack->sname2);
	des2src(tPhotoTmp.sex,rPack->smarket_code);
	des2src(tPhotoTmp.dept_code,rPack->scust_no);
	des2src(tPhotoTmp.s_code,rPack->scust_no2);
	des2src(tPhotoTmp.cur_grade,rPack->sorder0);
//	des2src(tCustomerTmp.status,rPack->scust_type);
	tPhotoTmp.is_inschool=rPack->lvol1;
	tPhotoTmp.status=rPack->lvol2;

	ret=DB_t_cif_phototmp_add(&tPhotoTmp);
	if(SQLCODE)
	{
		if(DB_REPEAT==SQLCODE)
		{
			if(1==tPhotoTmp.seqno)
			{
				//如果插入有冲突,则再重新生成新的批次号
				for(i=0;i<3;i++)
				{
					sleep(1);
					getsysdatetime(tPhotoTmp.batch_no);
					ret=DB_t_cif_phototmp_add(&tPhotoTmp);
					if(ret)
					{
						if(DB_REPEAT==SQLCODE)
							continue;
						else
						{
							*pRetCode=E_DB_PHOTOTMP_I;
							goto L_RETU;
						}
					}
					break;
				}
				if(i>=3)
				{
					writelog(LOG_ERR,"batch_no[%s]seqno[%d]",tPhotoTmp.batch_no,tPhotoTmp.seqno);
					*pRetCode=E_DB_PHOTOTMP_E;
					goto L_RETU;
				}
			}
			else
			{
				writelog(LOG_ERR,"batch_no[%s]seqno[%d]",tPhotoTmp.batch_no,tPhotoTmp.seqno);
				*pRetCode=E_DB_PHOTOTMP_E;
				goto L_RETU;
			}
		}
		else
		{
			writelog(LOG_ERR,"batch_no[%s]seqno[%d]",tPhotoTmp.batch_no,tPhotoTmp.seqno);
			*pRetCode=E_DB_PHOTOTMP_I;
			goto L_RETU;
		}
	}
	if(rPack->scust_type[0]=='1')
	{
		//最后一条,开始把临时表数据导入到照片表
		writelog(LOG_DEBUG,"导入第%d记录,批次号:%s,姓名:%s",tPhotoTmp.seqno,tPhotoTmp.batch_no,tPhotoTmp.stuemp_name);
		//因为照片库是联邦过来的,需要先提交事务,才能更新联邦数据库
		ret=db_commit();
		if(ret)
		{
			ret=E_DB_COMMIT;
			writelog(LOG_ERR,"db_commit ret[%d]",ret);
			goto L_RETU;
		}
		iCnt=0;
		ret=DB_t_cif_phototmp_open_select_by_c0_and_batch_no(tPhotoTmp.batch_no);
		while(1)
		{
			memset(&tPhotoTmpOut,0,sizeof(tPhotoTmpOut));
			ret=DB_t_cif_phototmp_fetch_select_by_c0(&tPhotoTmpOut);
			if(ret)
			{
				if(DB_NOTFOUND==ret)
				{
					if(iCnt>0)
						break;
					else
					{
						*pRetCode=E_DB_PHOTOTMP_N;
						goto L_RETU;
					}
				}
				else
				{
					*pRetCode=E_DB_PHOTOTMP_R;
					goto L_RETU;
				}
			}
			memset(&tYktPhoto,0,sizeof(tYktPhoto));
			//导入照片表
			des2src(tYktPhoto.cur_grade,tPhotoTmpOut.cur_grade);
			des2src(tYktPhoto.cut_type,tPhotoTmpOut.cut_type);
			des2src(tYktPhoto.dept_code,tPhotoTmpOut.dept_code);
			tYktPhoto.is_inschool=tPhotoTmpOut.is_inschool;
			des2src(tYktPhoto.sex,tPhotoTmpOut.sex);
			des2src(tYktPhoto.stuemp_name,tPhotoTmpOut.stuemp_name);
			des2src(tYktPhoto.stuemp_no,tPhotoTmpOut.stuemp_no);
			des2src(tYktPhoto.s_code,tPhotoTmpOut.s_code);
			ret=DB_t_cif_photo_add(&tYktPhoto);
			if(ret)
			{
				DB_t_cif_phototmp_close_select_by_c0();
				sprintf(szMsg,"批次号%s,第%d条姓名为%s的记录有误,不能导入.",tPhotoTmpOut.batch_no,tPhotoTmpOut.seqno,tPhotoTmp.stuemp_name);
				goto L_RETU;
			}
			++iCnt;
		}
		sprintf(out_pack->vsmess,"批次号:%s,共成功导入%d条客户信息",tPhotoTmp.batch_no,iCnt);
		flag=2;
	}
	if(flag!=2)
	{
		sprintf(out_pack->vsmess,"导入第%d记录,批次号:%s,姓名:%s",tPhotoTmp.seqno,tPhotoTmp.batch_no,tPhotoTmp.stuemp_name);
	}
	des2src(out_pack->scust_limit,tPhotoTmp.batch_no);
	PutRow(handle,out_pack,pRetCode,szMsg);
	writelog(LOG_DEBUG,out_pack->vsmess);
	return 0;
L_RETU:
	return -1;
}
Ejemplo n.º 6
0
int F930021(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg)
{
	int ret = 0;
	int cnt=0;
	int msgid=0;
   	T_t_msglist tMsgList;
	T_t_device	tDevice;
	T_t_device tPDev;

	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_VSVARSTR0,0);
	memset(&tMsgList,0,sizeof(tMsgList));
	memset(&tDevice,0,sizeof(tDevice));
	memset(&tPDev,0,sizeof tPDev);


	if(strlen(in_pack->sdate0)==0)
	{
		*pRetCode=E_DEVPHYID_NULL;
		goto L_RETU;
	}
	ret=get_devinfo_by_phyid(in_pack->sdate0,&tDevice);
	if(ret)
	{
		*pRetCode=ret;
		writelog(LOG_ERR,"get_devinfo_by_phyid err[%d]",ret);
		goto L_RETU;
	}

	if((ret = DB_t_device_read_by_deviceid(tDevice.fdeviceid,&tPDev)))
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	AddXmlItemStr(tMsgList.reqdata,XML_KEY_DEV999_ID, tDevice.devphyid);
	AddXmlItemInt(tMsgList.reqdata,XML_KEY_DEV999_NO,  tDevice.deviceno);
	AddXmlItemStr(tMsgList.reqdata,XML_KEY_DEVTYPE,tDevice.devtypecode);
	AddXmlItemStr(tMsgList.reqdata,XML_KEY_DEVVERSION, tDevice.devverno);
	AddXmlItemStr(tMsgList.reqdata,XML_KEY_CARDSTR, tDevice.cardphytype);
	AddXmlItemStr(tMsgList.reqdata,XML_KEY_VCARDSET, tDevice.cardset);
	AddXmlItemInt(tMsgList.reqdata, XML_KEY_PORTCOUNT, tDevice.svrportcnt);
	AddXmlItemStr(tMsgList.reqdata, XML_KEY_FDEVPHY_ID, tPDev.devphyid);
	AddXmlItemInt(tMsgList.reqdata, XML_KEY_PORTNO,tDevice.svrportno);
	AddXmlItemStr(tMsgList.reqdata, XML_KEY_status, tDevice.status);
	AddXmlItemInt(tMsgList.reqdata,XML_KEY_JOINMODE,tDevice.commtype);
	AddXmlItemStr(tMsgList.reqdata, XML_KEY_COMADD, tDevice.ip);
	AddXmlItemInt(tMsgList.reqdata, XML_KEY_PORT,  tDevice.portno);
	AddXmlItemInt(tMsgList.reqdata, XML_KEY_BAUDRATE, tDevice.baudrate);
	AddXmlItemInt(tMsgList.reqdata, XML_KEY_COMTYPE,tDevice.commtype);
	AddXmlItemStr(tMsgList.reqdata, XML_KEY_NOTVALIDITY, "091231000000");
	AddXmlItemStr(tMsgList.reqdata, XML_KEY_VERNUM,tDevice.cardverno);
//	AddXmlItemInt(tMsgList.reqdata, XML_KEY_LASTTRASERNO, tDevice.lasttraserno);
//	AddXmlItemStr(tMsgList.reqdata, XML_KEY_LASTTRADATE, tDevice.lasttradate);
//	AddXmlItemInt(tMsgList.reqdata, XML_KEY_LASTSHUTSERNO, tDevice.lastshutserno);
//	AddXmlItemStr(tMsgList.reqdata, XML_KEY_LASTSHUTDATE, tDevice.lastshutdate);
	tMsgList.deviceid = tDevice.deviceid;
	tMsgList.funcno = 930021;
	tMsgList.msglevel = 3;
	ret=AddMsgLst(&tMsgList);
	if(ret)
	{
		*pRetCode=ret;
		writelog(LOG_ERR,"AddMsgLst err[%d]",ret);
		goto L_RETU;
	}
	if(iRequest!=tMsgList.funcno)
		return 0;	
	ret=db_commit();
	if(ret)
	{
		writelog(LOG_ERR,"db_commit ret[%d]",ret);
		*pRetCode=E_DB_COMMIT;
		goto  L_RETU;
	}
	msgid=tMsgList.msgid;
	des2src(out_pack->sdate0,in_pack->sdate0);
	for(cnt=0;(cnt<10)&&(tMsgList.errcode!=0);cnt++)
	{
		sleep(1);
		memset(&tMsgList,0,sizeof(tMsgList));
		ret=DB_t_msglist_read_by_msgid(msgid, &tMsgList);
		if(ret)
		{
			writelog(LOG_ERR,"DB_t_msglist_read_by_msgid err[%d]",ret);
			*pRetCode=E_DB_MSGLIST_R;
			goto L_RETU;
		}
	}
	switch(tMsgList.errcode)
	{
		case 0:		//成功
			des2src(out_pack->vsvarstr0,"成功");
			break;
		case 9999:		//交易未处理
			des2src(out_pack->vsvarstr0,"前置机无应答");
			break;
		default:			//交易已经处理,但结果是失败
			des2src(out_pack->vsvarstr0,tMsgList.errmsg);				
			break;
	}	
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return  -1;	
}
Ejemplo n.º 7
0
int F930004(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg)
{
	int ret = 0;
	int cnt=0;
	int mesid=0;
  	char sCardState[5]="";
     	T_t_tif_meslist tMesList;

	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_VSVARSTR0,0);
	memset(&tMesList,0,sizeof(tMesList));

	des2src(tMesList.devphy999_id, in_pack->sdate0);
	trim(tMesList.devphy999_id);
	if(strlen(tMesList.devphy999_id)==0)
	{
		*pRetCode=E_DEVPHYID_NULL;
		goto L_RETU;
	}

	ret=GetCardState(in_pack->lvol0,sCardState);
	if (ret)
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	if('2'==sCardState[CARDSTAT_TYPE_REG])
	{
		*pRetCode = E_CARDNO_LOGOUT;
		goto L_RETU;
	}
	if(STATE_TRUE==sCardState[CARDSTAT_TYPE_FREEZE])
	{
		*pRetCode = E_CARDNO_FREEZE;
		goto L_RETU;
	}
	AddXmlItemInt(tMesList.incontent, XML_KEY_CARDID,in_pack->lvol0);
	AddXmlItemStr(tMesList.incontent, XML_KEY_VERNUM, in_pack->sserial0);

	tMesList.funid = 930004;
	tMesList.level = 1;
	ret=AddMsgLst(&tMesList);
	if(ret)
	{
		*pRetCode=ret;
		writelog(LOG_ERR,"AddMsgLst err[%d]",ret);
		goto L_RETU;
	}
	if(iRequest!=tMesList.funid)
		return 0;
	ret=db_commit();
	if(ret)
	{
		writelog(LOG_ERR,"db_commit ret[%d]",ret);
		*pRetCode=E_DB_COMMIT;
		goto  L_RETU;
	}
	mesid=tMesList.mesid;
	des2src(out_pack->sdate0,in_pack->sdate0);
	for(cnt=0;(cnt<10)&&(tMesList.ecode!=0);cnt++)
	{
		sleep(1);
		memset(&tMesList,0,sizeof(tMesList));
		ret=DB_t_tif_meslist_read_by_mesid(mesid, &tMesList);
		if(ret)
		{
			writelog(LOG_ERR,"DB_t_tif_meslist_read_by_mesid err[%d]",ret);
			*pRetCode=E_DB_MESLIST_R;
			goto L_RETU;
		}
	}
	switch(tMesList.ecode)
	{
		case 0:		//成功
			des2src(out_pack->vsvarstr0,"成功");
			break;
		case 9999:		//交易未处理
			des2src(out_pack->vsvarstr0,"前置机无应答");
			break;
		default:			//交易已经处理,但结果是失败
			des2src(out_pack->vsvarstr0,tMesList.emsg);
			break;
	}
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return  -1;
}
Ejemplo n.º 8
0
 int record_serial(ST_PACK *in_pack,T_t_tif_tradeserial *tradeserial,ST_PACK *out_pack){
	int ret =0;
	int card_id= 0;
	double dUniqno = 0;
	char logicdate[11]="";
	char sysdate[11]="";
	char systime[9]="";
	char	Operator[33+1] = "";
	int	maindevice_id = 0;

	T_t_pif_card tCard;
	card_id=in_pack->lvol0;

	memset(&tCard,0,sizeof(tCard));
	
	ret=get_datetime_from_db(sysdate,systime);
	if(ret)
	{
		writelog(LOG_ERR,"get_datetime_from_db error,error code=[%d]",ret);
		getsysdate(sysdate);
		getsystime(systime);
		return ret;
	}
	ret=GetLogicDate(logicdate);								//业务日期
	if(ret)
	{
		writelog(LOG_ERR,"GetLogicDate error,errcode=[%d]",ret);
		return ret;
	}

	ret=DB_t_pif_card_read_by_card_id(card_id, &tCard);
	if(ret)
	{
		if(DB_NOTFOUND==ret)
			ret=E_CARDNO_NOT_EXIST;
		else
			ret=E_DB_CARD_R;
		return ret;
	}

	if(strncmp(tCard.state_id,CARDSTAT_REG,4)!=0)
	{
		if('2'==tCard.state_id[CARDSTAT_TYPE_REG])
			ret= E_CARDNO_LOGOUT;
		else if('3'==tCard.state_id[CARDSTAT_TYPE_REG])
			ret = E_CARD_CHANGE;
		else if(tCard.state_id[CARDSTAT_TYPE_LOST]==STATE_TRUE)
			ret=E_CARDNO_LOST;
		else if(tCard.state_id[CARDSTAT_TYPE_FREEZE]==STATE_TRUE)
			ret=E_CARDNO_FREEZE;
		else if(tCard.state_id[CARDSTAT_TYPE_WFAIL]==STATE_TRUE)
			ret=E_CARDNO_WFAIL;
		return ret;
	}
	//	准备数据插入交易流水表
	ret = getNewUniqNo(KEYTYPE_TRADESERIAL,&dUniqno);  					//获得最大流水号
	if(ret)
	{
		writelog(LOG_ERR,"getNewUniqNo error,errcode=[%d]",ret);
		return ret;
	}						
	tradeserial->serial_no = D2I(dUniqno);			//流水号

	if(strlen(in_pack->scust_no) ==0)
		return E_INPUT_OPER_NULL;
	des2src(Operator,in_pack->scust_no);					//操作员号								//采集设备标识

	strncpy(tradeserial->operate_date,sysdate,sizeof(sysdate)-1);				//发生日期
	strncpy(tradeserial->operate_time,systime,sizeof(systime)-1);
	des2src(tradeserial->collect_date,tradeserial->operate_date);								//采集日期
	des2src(tradeserial->collect_time,tradeserial->operate_time);								//采集时间
	des2src(tradeserial->enteract_date,logicdate);							//处理日期
	des2src(tradeserial->enteract_time,tradeserial->operate_time);							//处理时间
	tradeserial->serial_no = D2I(dUniqno);									//流水号
	tradeserial->purse_id = PURSE_NO_ONE;					//钱包号
	tradeserial->serial_state = SERISTAT_NODEBT;								//流水状态
	tradeserial->maindevice_id = maindevice_id;						//上传工作站标识
	tradeserial->device_id = in_pack->lvol4;										//采集设备标识
	tradeserial->card_id = card_id;										//交易卡号
	tradeserial->customer_id=tCard.cosumer_id;								//客户号
	des2src(tradeserial->oper_code,Operator);
	tradeserial->trade_count=in_pack->lvol1+1;		//交易次数
	tradeserial->in_balance=in_pack->damt0;			//入卡值


	//除了海事的考试报名,别的交易金额不能小于0
	if(amtcmp(in_pack->damt1, 0) <= 0)
	{
		if(tradeserial->serial_type != 847233)
			return E_INPUT_AMT_NULL;
	}
	tradeserial->trade_fee=in_pack->damt1;				//交易金额
	strncpy(tradeserial->reserve_2,in_pack->vsmess,sizeof(tradeserial->reserve_2)-1);

	ret = DB_t_tif_tradeserial_add(tradeserial);
	if (ret)
	{
		writelog(LOG_ERR,"ret[%d]",ret);
		if(DB_REPEAT==ret)
			ret = E_DB_TRADESERIAL_E;
		else
			ret = E_DB_TRADESERIAL_I;
		return ret;
	}
	ret=db_commit();
	if(ret)
	{
		writelog(LOG_ERR,"db_commit error,errcode=[%d]",ret);
		return E_DB_COMMIT;
	}
	return 0;
	

}	
Ejemplo n.º 9
0
Archivo: brain.c Proyecto: lp0/sqlhal
int main(int argc, char *argv[]) {
	char *action;
	char *name;
	char *prefix;
	int ret;
	int fail = 0;
	char *state;

	if (argc != 4 || (strcmp(argv[1], "load") && strcmp(argv[1], "save") && strcmp(argv[1], "save+"))) {
		printf("Brain manipulation\n");
		printf("Usage: %s load  <name> <filename prefix>\n", argv[0]);
		printf("       %s save  <name> <filename prefix>\n", argv[0]);
		printf("       %s save+ <name> <filename prefix>\n", argv[0]);
		return 1;
	}

	action = argv[1];
	name = argv[2];
	prefix = argv[3];

	state = "db_connect";
	ret = db_connect();
	if (ret) goto fail;
	else log_info("brain", ret, state);

	state = "db_begin";
	ret = db_begin();
	if (ret) goto fail;
	else log_info("brain", ret, state);

	if (!strcmp(action, "load")) {
		state = "input_list aux";
		ret = input_list(name, prefix, "aux", LIST_AUX);
		if (ret) { log_warn("brain", ret, state); fail = 1; }
		else log_info("brain", ret, state);

		state = "input_list ban";
		ret = input_list(name, prefix, "ban", LIST_BAN);
		if (ret) { log_warn("brain", ret, state); fail = 1; }
		else log_info("brain", ret, state);

		state = "input_list grt";
		ret = input_list(name, prefix, "grt", LIST_GREET);
		if (ret) { log_warn("brain", ret, state); fail = 1; }
		else log_info("brain", ret, state);

		state = "input_map swp";
		ret = input_map(name, prefix, "swp", MAP_SWAP);
		if (ret) { log_warn("brain", ret, state); fail = 1; }
		else log_info("brain", ret, state);

		state = "input_brain";
		ret = input_brain(name, prefix);
		if (ret) { log_warn("brain", ret, state); fail = 1; }
		else log_info("brain", ret, state);
	} else if (!strcmp(action, "save") || !strcmp(action, "save+")) {
		enum file_type type = FILETYPE_MEGAHAL8;
		if (!strcmp(action, "save+"))
			type = FILETYPE_SQLHAL0;

		state = "output_list aux";
		ret = output_list(name, prefix, "aux", LIST_AUX);
		if (ret) { log_warn("brain", ret, state); fail = 1; }
		else log_info("brain", ret, state);

		state = "output_list ban";
		ret = output_list(name, prefix, "ban", LIST_BAN);
		if (ret) { log_warn("brain", ret, state); fail = 1; }
		else log_info("brain", ret, state);

		state = "output_list grt";
		ret = output_list(name, prefix, "grt", LIST_GREET);
		if (ret) { log_warn("brain", ret, state); fail = 1; }
		else log_info("brain", ret, state);

		state = "output_map swp";
		ret = output_map(name, prefix, "swp", MAP_SWAP);
		if (ret) { log_warn("brain", ret, state); fail = 1; }
		else log_info("brain", ret, state);

		state = "output_brain";
		ret = output_brain(name, type, prefix);
		if (ret) { log_warn("brain", ret, state); fail = 1; }
		else log_info("brain", ret, state);
	} else {
		fail = 1;
	}

	if (fail) {
		state = "db_rollback";
		ret = db_rollback();
		if (ret) goto fail;
		else log_info("brain", ret, state);
	} else {
		state = "db_commit";
		ret = db_commit();
		if (ret) goto fail;
		else log_info("brain", ret, state);
	}

	state = "db_disconnect";
	ret = db_disconnect();
	if (ret) goto fail;
	else log_info("brain", ret, state);

	return 0;

fail:
	log_fatal("brain", ret, state);
	return 1;
}
Ejemplo n.º 10
0
int Do_Compare_file_shoudong()
{
///*
	FILE *fp;
	TIniFile tf;
	char path_name[256]="";
	char file_name[256]="";
	int ret=0;
	int cnt=0;
	int i=0;

	BANK_COMPARE_RECODE compare,compare1;
	T_t_tif_bank_comp	bank_comp;
	T_t_tif_report_trans_comp trans_comp;
	T_t_tif_tradeserial	tradeserial;
	T_t_tif_tradeserial_his his_tradeserial;
	T_t_tif_diff_transfer  diff_transfer;

	char logicdate[10]="";
	char tmp_date[10]="";
	char forward_date[10]="";

	double trans_count=0;
	double bank_count=0;
	double trans_amt=0;
	double bank_amt=0;
	double second=0;

	double temp=0;
	char *p=getenv("BIN_PATH");

	ret=GetLogicDate(logicdate);								//业务日期
	if(ret)
	{
		writelog(LOG_ERR,"GetLogicDate error,errcode=[%d]",ret);
		return ret;
	}

	ret=datetime2second(logicdate, "YYYYMMDD", &second);
	if(ret)
	{
		writelog(LOG_ERR,"datetime2second error,errcode=[%d]",ret);
		return 	ret;
	}
	 //trans_count=0;
	 //bank_count=0;
	 //trans_amt=0;
	// bank_amt=0;

	second=second-24*60*60;
	ret=second2datetime(second, forward_date, "YYYYMMDD");
	if(ret)
	{
		writelog(LOG_ERR,"second2datetime error,errcode=[%d]",ret);
		return 	ret;
	}

	memset(&bank_comp,0,sizeof(bank_comp));
	memset(&compare,0,sizeof(compare));
	memset(&trans_comp,0,sizeof(trans_comp));
	memset(&tradeserial,0,sizeof(tradeserial));
	memset(&his_tradeserial,0,sizeof(his_tradeserial));

	memset(&compare1,0x30,sizeof(compare1));

	ret=DB_t_tif_report_trans_comp_read_by_cmp_date(forward_date,&trans_comp);
	if(ret!=100&&ret!=0)
	{
		writelog(LOG_ERR,"DB_t_tif_report_trans_comp_read_by_cmp_date error,errcode=[%d]",ret);
		goto LRet;
	}
	if(1==trans_comp.cmp_flag)
	{
		writelog(LOG_ERR,"trans_comp.cmp_flag =1,already compare!");
		goto LRet;
	}
	//配置环境变量
	if(p==NULL)
	{
	   	writelog(LOG_ERR,"Cann't get env HOME PATH\n");
	   	return -1;
	}
	//sprintf(path_name,"%s/ftp",p);
	sprintf(path_name,"%s",p);
	//strcpy(path_name,"/bank/ykt/src/bank/ftp");
	sprintf(file_name,"%s/XYK00002.%8.8s",path_name,forward_date);
	writelog(LOG_ERR,"Open indirect file=[%s]",file_name);
	if((fp = fopen(file_name,"rb"))==NULL)
	{
		writelog(LOG_ERR,"Open indirect file error,file=[%s]",file_name);
		return	-1;
	}

	while(!feof(fp))
	{
		memset(&bank_comp,0,sizeof(bank_comp));
		memset(&compare,0,sizeof(compare));
		cnt++;
		if(NULL==fgets((char *)(&compare),sizeof(compare),fp))
		{
			writelog(LOG_ERR,"fgets error,");
			continue;
		}
		//不知道为什么,必须要跳一个才能对?
		if((cnt+2)%2==0)	continue;
		//开始进行赋值
		if(memcmp(&compare,&compare1,10)==0)	break;
		else
		{
			strncpy(bank_comp.op_date,forward_date,sizeof(bank_comp.op_date)-1);
			memcpy(bank_comp.tx_code,compare.TradeCode,2);
			bank_comp.card_id=atoi(compare.GDCAccount);
			memcpy(bank_comp.bankcard,compare.BankCard,20);
			bank_comp.local_sn=atoi(compare.LocalSn);
			//printf("--------local_sn[%d]=[%d]\n",cnt,bank_comp.local_sn);
			memcpy(bank_comp.bank_sn,compare.BankSn,20);
			strncpy(bank_comp.trans_money,compare.TransMomoy,9);

			ret=DB_t_tif_bank_comp_add(&bank_comp);
			if(ret)
			{
				writelog(LOG_ERR,"DB_t_tif_bank_comp_add rows[%d] error,errcode=[%d]",cnt,ret);
				goto LRet;
			}
		}
	}
	//读取对帐文件结束,关闭对仗文件,提交事务
	//printf("Line=[%d]\n",__LINE__);
	if(fclose(fp))
	{
		writelog(LOG_ERR,"Close file error,file=[%s]",file_name);
		goto LRet;
	}
	ret=db_commit();
	if(ret)
	{
		writelog(LOG_ERR,"db_commit error,errcode=[%d]",ret);
		goto LRet;
	}

	//开始进行对帐
	cnt=0;

	//对总数
	ret=DB_his_t_tif_tradeserial_get_count_by_serial_type(&temp,240001,forward_date);
	if(ret!=100&&ret!=0)
	{
		writelog(LOG_ERR,"DB_t_tif_tradeserial_get_count_by_serial_type err,errcode=[%d]",ret);
		goto LRet;
	}
	trans_count=trans_count+temp;
	trans_comp.localself_num=trans_count;

	ret=DB_his_t_tif_tradeserial_get_sum_by_serial_type(&temp, 240001, forward_date);
	if(ret!=100&&ret!=0)
	{
		writelog(LOG_ERR,"DB_his_t_tif_tradeserial_get_sum_by_serial_type err,errcode=[%d]",ret);
		goto LRet;
	}
	trans_amt=trans_amt+temp;
	trans_comp.localself_amt=trans_amt;

	ret=DB_t_tif_bank_comp_open_select_by_cur1_and_op_date(forward_date);
	if(ret)
	{
		writelog(LOG_ERR,"DB_t_tif_bank_comp_open_select_by_cur1_and_op_date err,errcode=[%d]",ret);
		goto LRet;
	}
	while(1)
	{
		ret=DB_t_tif_bank_comp_fetch_select_by_cur1(&bank_comp);
		if(ret)
		{
			DB_t_tif_bank_comp_close_select_by_cur1();
			if(ret==DB_NOTFOUND)
			{
				if(cnt==0)
					{
						writelog(LOG_DEBUG,"There havn't record from t_tif_bankcomp table!");
						break;
					}
				else		break;
			}
			else
				goto LRet;
		}
		cnt++;
		bank_count=bank_count+1;
		bank_amt=bank_amt+atof(bank_comp.trans_money)/100.00;
		memset(&diff_transfer,0,sizeof(diff_transfer));
		//printf("Line=[%d],cnt=[%d]\n",__LINE__,cnt);

		ret=DB_t_tif_tradeserial_his_read_by_bak_date_and_serial_no(forward_date,bank_comp.local_sn,&his_tradeserial);
		//流水表中没有记录的情况
		if(ret)
		{
			if(100==ret)
			{
				strncpy(diff_transfer.op_date,forward_date,sizeof(diff_transfer.op_date)-1);
				strncpy(diff_transfer.bankcard,bank_comp.bankcard,sizeof(diff_transfer.bankcard)-1);
				diff_transfer.bank_amt=atoi(bank_comp.trans_money)/100.00;
				strncpy(diff_transfer.bank_sn,bank_comp.bank_sn,sizeof(diff_transfer.bank_sn)-1);
				diff_transfer.card_id=bank_comp.card_id;
				diff_transfer.local_sn=bank_comp.local_sn;
				diff_transfer.diff_amt=diff_transfer.bank_amt-diff_transfer.local_amt;
				diff_transfer.status=1;
				ret=DB_t_tif_diff_transfer_add(&diff_transfer);
				if(ret)
				{
					writelog(LOG_ERR,"DB_t_tif_diff_transfer_add error,errcode=[%d]!",ret);
					break;
				}
				continue;
			}
			else
			{
				writelog(LOG_ERR,"DB_t_tif_tradeserial_his_read_lock_by_c0_and_enteract_date_and_serial_no error,errcode=[%d]!",ret);
				break;
			}
		}
		//流水表中存在,但是没有入账的情况
		if(his_tradeserial.serial_state!=2)
		{
				strncpy(diff_transfer.op_date,forward_date,sizeof(diff_transfer.op_date)-1);
				strncpy(diff_transfer.bankcard,bank_comp.bankcard,sizeof(diff_transfer.bankcard)-1);
				diff_transfer.bank_amt=atoi(bank_comp.trans_money)/100.00;
				strncpy(diff_transfer.bank_sn,bank_comp.bank_sn,sizeof(diff_transfer.bank_sn)-1);
				diff_transfer.card_id=bank_comp.card_id;
				diff_transfer.local_amt=0;
				diff_transfer.local_sn=bank_comp.local_sn;
				diff_transfer.diff_amt=diff_transfer.bank_amt-diff_transfer.local_amt;
				diff_transfer.status=1;
				ret=DB_t_tif_diff_transfer_add(&diff_transfer);
				if(ret)
				{
					writelog(LOG_ERR,"DB_t_tif_diff_transfer_add error,errcode=[%d]!",ret);
					break;
				}
		}
	}

	trans_comp.bankself_amt=bank_amt;
	trans_comp.bankself_num=bank_count;
	trans_comp.localself_amt=trans_amt;
	trans_comp.localself_num=trans_count;
	trans_comp.cmp_flag=1;
	strncpy(trans_comp.cmp_date,forward_date,sizeof(trans_comp.cmp_date)-1);
	ret=DB_t_tif_report_trans_comp_add(&trans_comp);
	if(ret)
	{
		writelog(LOG_DEBUG,"DB_t_tif_report_trans_comp_add error,errcode=[%d]",ret);
		goto LRet;

	}

	ret=db_commit();
	if(ret)
	{
		writelog(LOG_ERR,"db_commit error,errcode=[%d]",ret);
		goto LRet;
	}
	return 0;

LRet:
	db_rollback();
	return ret;

	//*/
}
Ejemplo n.º 11
0
/* ****** Updated by CHENYH at 2004-4-9 10:06:44 ******
   增加pArrays: 为了能够接收处理多请求记录的情况
*/
int CallBDFunc(int fno,TRUSERID *handle,ST_CPACK *rpack,ST_PACK *pArrays,int *iRetCode, char *szMsg)
{
   int r=0;
   int rtn=0;
   int sendtype=0;
   char param[101]="";
#ifdef _DEBUG1
CMemoryState cm1, cm2, cm3;
#endif
   APPFUNC pFunc = g_BDefines[fno].pFunc;

#ifdef _DEBUG1
	cm1.Checkpoint();
#endif
	*iRetCode=0;
	*szMsg=0;
	//判断是否是结帐时刻,如果是则等待处理
	sendtype=rpack->head.RequestType/10000;
	switch(sendtype)
       {
		case 93:
		case 95:
			rtn = (*pFunc)(handle,rpack->head.RequestType,&rpack->pack,iRetCode,szMsg);
			break;
		default:
		 	rtn=GetSysParaVal(GLOBE_FLAG_BALANCE,param);
			if(rtn)
			{
				*iRetCode=rtn;
				break;
			}
			else if(strncmp(param,"0",1)!=0)
			{
				rtn=E_DAYEND_STATUS;
				*iRetCode=rtn;
				break;
			}
			rtn = (*pFunc)(handle,rpack->head.RequestType,&rpack->pack,iRetCode,szMsg);
	              break;
       }
	if(rtn)
	{
	   	char sErrMsg[101]="";
		char sRetMsg[256]="";
		if(*szMsg)
			snprintf(sRetMsg,256," %s",szMsg);
		r=get_errcode_msg(*iRetCode, sErrMsg);
		db_rollback();
		snprintf(szMsg,256,"%s%s",sErrMsg,sRetMsg);
		writelog(LOG_ERR,"Func[%d]ecode[%d]msg[%s]",rpack->head.RequestType,*iRetCode,szMsg);
		ERR_DEAL(szMsg,*iRetCode);
		if(r)
		{
			AnswerData(handle,*iRetCode,szMsg);
			db_disconnect();
			writelog(LOG_ERR,"数据库错误,系统退出");
			exit(1);
		}
	}
	else
	{
		r=db_commit();
		if(r)
		{
			*iRetCode=E_DB_COMMIT;
			strcpy(szMsg,"数据库事务提交失败");
			writelog(LOG_ERR,"Func[%d]Msg[%s]",rpack->head.RequestType,szMsg);
			db_rollback();
			ERR_DEAL( szMsg,*iRetCode);
		}
	}
#ifdef _DEBUG1
	cm2.Checkpoint();
	if (cm3.Difference(cm1, cm2))
   {
      BCCMsgLogOut(14444,"在执行功能号:%u时候,经检查,内存出现错误!",rpack->head.RequestType);
      g_LogFile.WriteLogEx(14444,"在执行功能号:%u时候,经检查,内存出现错误!",rpack->head.RequestType);
		cm3.DumpStatistics();
   }
#endif

   if (g_BUnit.m_SqlDB.lErrorCode<=-10000)  // 出现SQL比较严重的错误
   {
      if (SQLIsConnectOK()==0)
      {
         SQLDisconnect();
      }
      g_BUnit.m_SqlDB.lErrorCode = 0;
   }
   return(rtn);
}
Ejemplo n.º 12
0
int F930061(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg)
{
	int ret = 0;
	int cnt=0;
	int msgid=0;
 	T_t_msglist tMsgList;
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_VSVARSTR0,0);
	memset(&tMsgList,0,sizeof(tMsgList));
	if(strlen(in_pack->sdate0)==0)
	{
		return E_DEVPHYID_NULL;
	}
	ret=GetDeviceidByDevphyid(in_pack->sdate0,&(tMsgList.deviceid));
	if(ret)
	{
		return ret;
	}
	AddXmlItemInt(tMsgList.reqdata, XML_KEY_MAXTRADE, in_pack->lvol4);
	tMsgList.funcno = 930061;
	tMsgList.msglevel = 2;
	ret=AddMsgLst(&tMsgList);
	if(ret)
	{
		*pRetCode=ret;
		writelog(LOG_ERR,"AddMsgLst err[%d]",ret);
		goto L_RETU;
	}
	if(iRequest!=tMsgList.funcno)
		return 0;	
	ret=db_commit();
	if(ret)
	{
		writelog(LOG_ERR,"db_commit ret[%d]",ret);
		*pRetCode=E_DB_COMMIT;
		goto  L_RETU;
	}
	msgid=tMsgList.msgid;
	des2src(out_pack->sdate0,in_pack->sdate0);
	for(cnt=0;(cnt<10)&&(tMsgList.errcode!=0);cnt++)
	{
		sleep(1);
		memset(&tMsgList,0,sizeof(tMsgList));
		ret=DB_t_msglist_read_by_msgid(msgid, &tMsgList);
		if(ret)
		{
			writelog(LOG_ERR,"DB_t_msglist_read_by_msgid err[%d]",ret);
			*pRetCode=E_DB_MSGLIST_R;
			goto L_RETU;
		}
	}
	switch(tMsgList.errcode)
	{
		case 0:		//成功
			des2src(out_pack->vsvarstr0,"成功");
			break;
		case 9999:		//交易未处理
			des2src(out_pack->vsvarstr0,"前置机无应答");
			break;
		default:			//交易已经处理,但结果是失败
			des2src(out_pack->vsvarstr0,tMsgList.errmsg);				
			break;
	}	
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return  -1;	
}
Ejemplo n.º 13
0
int db_connect(void) {
	if (conn == NULL) {
		conn = PQconnectdb("");

		if (conn == NULL)
			return -EDB;

		if (PQstatus(conn) != CONNECTION_OK) {
			log_error("DB", PQstatus(conn), PQerrorMessage(conn));
			PQfinish(conn);
			conn = NULL;
		} else {
			PGresult *res = NULL;
			const char *brains[] = { "brains" };
			const char *words[] = { "words" };
			const char *lists[] = { "lists" };
			const char *maps[] = { "maps" };
			const char *models[] = { "models" };
			const char *nodes[] = { "nodes" };
			int nodes_created = 0;
			int server_ver;

			server_ver = PQserverVersion(conn);
			if (server_ver < 80400) {
				log_error("DB", server_ver, "Server version must be 8.4.0+");
				PQfinish(conn);
				conn = NULL;
				return -EDB;
			}

			if (db_begin()) goto fail2;

			res = PQprepare(conn, "table_exists", "SELECT tablename FROM pg_tables WHERE schemaname = 'public' AND tablename = $1", 1, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			/* BRAIN */

			res = PQexecPrepared(conn, "table_exists", 1, brains, NULL, NULL, 1);
			if (PQresultStatus(res) != PGRES_TUPLES_OK) goto fail;
			if (PQntuples(res) != 1) {
				PQclear(res);

				res = PQexec(conn, "CREATE TABLE brains (id BIGSERIAL UNIQUE, name TEXT,"\
					" PRIMARY KEY (name),"\
					" CONSTRAINT valid_id CHECK (id > 0))");
				if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			}
			PQclear(res);

			/* WORD */

			res = PQexecPrepared(conn, "table_exists", 1, words, NULL, NULL, 1);
			if (PQresultStatus(res) != PGRES_TUPLES_OK) goto fail;
			if (PQntuples(res) != 1) {
				PQclear(res);

				res = PQexec(conn, "CREATE TABLE words (id SERIAL UNIQUE, word TEXT, added TIMESTAMP NOT NULL DEFAULT NOW(),"\
					" PRIMARY KEY (word),"\
					" CONSTRAINT valid_id CHECK (id > 0))");
				if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			}
			PQclear(res);

			/* LIST */

			res = PQexecPrepared(conn, "table_exists", 1, lists, NULL, NULL, 1);
			if (PQresultStatus(res) != PGRES_TUPLES_OK) goto fail;
			if (PQntuples(res) != 1) {
				PQclear(res);

				res = PQexec(conn, "CREATE TABLE lists (type INT NOT NULL, brain BIGINT NOT NULL, word BIGINT NOT NULL,"\
					" PRIMARY KEY (brain, type, word),"\
					" FOREIGN KEY (brain) REFERENCES brains (id) ON UPDATE CASCADE ON DELETE CASCADE,"\
					" FOREIGN KEY (word) REFERENCES words (id) ON UPDATE CASCADE ON DELETE CASCADE,"\
					" CONSTRAINT valid_type CHECK (type >= 1 AND type <= 3))");
				if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
				PQclear(res);

				res = PQexec(conn, "CREATE INDEX lists_words ON lists (word)");
				if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			}
			PQclear(res);

			/* MAP */

			res = PQexecPrepared(conn, "table_exists", 1, maps, NULL, NULL, 1);
			if (PQresultStatus(res) != PGRES_TUPLES_OK) goto fail;
			if (PQntuples(res) != 1) {
				PQclear(res);

				res = PQexec(conn, "CREATE TABLE maps (type INT NOT NULL, brain BIGINT NOT NULL, key BIGINT NOT NULL, value BIGINT NOT NULL,"\
					" PRIMARY KEY (brain, key),"\
					" FOREIGN KEY (brain) REFERENCES brains (id) ON UPDATE CASCADE ON DELETE CASCADE,"\
					" FOREIGN KEY (key) REFERENCES words (id) ON UPDATE CASCADE ON DELETE CASCADE,"\
					" FOREIGN KEY (value) REFERENCES words (id) ON UPDATE CASCADE ON DELETE CASCADE,"\
					" CONSTRAINT valid_type CHECK (type = 4))");
				if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
				PQclear(res);

				res = PQexec(conn, "CREATE INDEX maps_keys ON maps (key)");
				if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
				PQclear(res);

				res = PQexec(conn, "CREATE INDEX maps_values ON maps (value)");
				if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			}
			PQclear(res);

			/* MODEL */

			res = PQexecPrepared(conn, "table_exists", 1, nodes, NULL, NULL, 1);
			if (PQresultStatus(res) != PGRES_TUPLES_OK) goto fail;
			if (PQntuples(res) != 1) {
				PQclear(res);

				res = PQexec(conn, "CREATE TABLE nodes (id BIGSERIAL UNIQUE, brain BIGINT NOT NULL, parent BIGINT, word BIGINT, usage BIGINT NOT NULL, count BIGINT NOT NULL,"\
					" PRIMARY KEY (brain, id),"\
					" FOREIGN KEY (parent) REFERENCES nodes (id) ON UPDATE CASCADE ON DELETE CASCADE,"\
					" FOREIGN KEY (word) REFERENCES words (id) ON UPDATE CASCADE ON DELETE CASCADE,"\
					" CONSTRAINT valid_id CHECK (id > 0),"\
					" CONSTRAINT valid_usage CHECK (usage >= 0),"\
					" CONSTRAINT valid_count CHECK (count >= 0),"\
					" CONSTRAINT valid_root CHECK (parent IS NOT NULL OR word IS NULL),"\
					" CONSTRAINT valid_fin CHECK (parent IS NULL OR word IS NOT NULL OR usage = 0))");
				if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
				PQclear(res);

				res = PQexec(conn, "CREATE INDEX nodes_words ON nodes (word)");
				if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
				PQclear(res);

				res = PQexec(conn, "CREATE UNIQUE INDEX nodes_child ON nodes (parent, word)");
				if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;

				nodes_created = 1;
			}
			PQclear(res);

			res = PQexecPrepared(conn, "table_exists", 1, models, NULL, NULL, 1);
			if (PQresultStatus(res) != PGRES_TUPLES_OK) goto fail;
			if (PQntuples(res) != 1) {
				PQclear(res);

				res = PQexec(conn, "CREATE TABLE models (brain BIGINT NOT NULL, contexts BIGINT NOT NULL, forward BIGINT, backward BIGINT,"\
					" PRIMARY KEY (brain),"\
					" FOREIGN KEY (brain) REFERENCES brains (id) ON UPDATE CASCADE ON DELETE CASCADE,"\
					" FOREIGN KEY (forward) REFERENCES nodes (id),"\
					" FOREIGN KEY (backward) REFERENCES nodes (id),"\
					" CONSTRAINT valid_order CHECK (contexts >= 0))");
				if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			}
			PQclear(res);

			if (nodes_created) {
				res = PQexec(conn, "ALTER TABLE nodes"\
					" ADD FOREIGN KEY (brain) REFERENCES models (brain) ON UPDATE CASCADE ON DELETE CASCADE");
				if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
				PQclear(res);
			}

			/* BRAIN */

			res = PQprepare(conn, "brain_add", "INSERT INTO brains (name) VALUES($1)", 1, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "brain_add_id", "SELECT currval('brains_id_seq')", 0, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "brain_get", "SELECT id FROM brains WHERE name = $1", 1, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			/* WORD */

			res = PQprepare(conn, "word_add", "INSERT INTO words (word) VALUES($1)", 1, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "word_add_id", "SELECT currval('words_id_seq')", 0, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "word_get", "SELECT id FROM words WHERE word = $1", 1, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "word_str", "SELECT word FROM words WHERE id = $1", 1, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			/* LIST */

			res = PQprepare(conn, "list_add", "INSERT INTO lists (brain, type, word) VALUES($1, $2, $3)", 3, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "list_get", "SELECT word FROM lists WHERE brain = $1 AND type = $2 AND word = $3", 3, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "list_iter", "SELECT lists.word, words.word FROM lists, words"\
				" WHERE brain = $1 AND type = $2 AND words.id = lists.word"\
				" ORDER BY words.word NULLS LAST", 2, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "list_zap", "DELETE FROM lists WHERE brain = $1 AND type = $2", 2, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			/* MAP */

			res = PQprepare(conn, "map_add", "INSERT INTO maps (brain, type, key, value) VALUES($1, $2, $3, $4)", 4, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "map_get", "SELECT value FROM maps WHERE brain = $1 AND type = $2 AND key = $3", 3, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "map_iter", "SELECT maps.key, maps.value, words_k.word, words_v.word"\
				" FROM maps, words AS words_k, words AS words_v"\
				" WHERE brain = $1 AND type = $2 AND words_k.id = maps.key AND words_v.id = maps.value"\
				" ORDER BY words_k.word NULLS LAST", 2, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "map_zap", "DELETE FROM maps WHERE brain = $1 AND type = $2", 2, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			/* MODEL */

			res = PQprepare(conn, "model_add", "INSERT INTO models (brain, contexts) VALUES($1, $2)", 2, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_get", "SELECT contexts FROM models WHERE brain = $1", 1, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_set", "UPDATE models SET contexts = $2 WHERE brain = $1", 1, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_zap", "DELETE FROM models WHERE brain = $1", 1, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_create", "INSERT INTO nodes (brain, usage, count) VALUES($1, 0, 0)", 1, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_fastcreate", "INSERT INTO nodes (brain, usage, count, word, parent) VALUES($1, $2, $3, $4, $5)", 5, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_create_id", "SELECT currval('nodes_id_seq')", 0, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_rootupdate", "UPDATE nodes SET parent = NULL, usage = $2, count = $3 WHERE id = $1", 3, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_update", "UPDATE nodes SET usage = $2, count = $3 WHERE id = $1", 3, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_root_get", "SELECT forward, backward FROM models WHERE brain = $1", 1, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_root_set", "UPDATE models SET forward = $2, backward = $3 WHERE brain = $1", 3, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_node_get", "SELECT id, word, usage, count FROM nodes"\
				" WHERE brain = $1 AND (id = $2 OR parent = $2)"\
				" ORDER BY (SELECT words.word FROM words WHERE words.id = nodes.word) NULLS LAST", 2, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_node_find", "SELECT id, word, usage, count FROM nodes"\
				" WHERE brain = $1 AND parent = $2 AND word = $3", 3, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_word_exists", "SELECT word FROM nodes WHERE brain = $1 AND word = $2 LIMIT 1", 2, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_word_random", "SELECT word FROM nodes WHERE brain = $1 AND parent = $2"\
				" ORDER BY random() LIMIT 1", 2, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_node_random", "SELECT id, word, usage, count FROM nodes"\
				" WHERE brain = $1 AND parent = $2"\
				" ORDER BY random() LIMIT 1", 2, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_node_first", "SELECT id, parent, word, usage, count FROM nodes"\
				" WHERE brain = $1 AND parent = $2"\
				" ORDER BY id LIMIT 1", 2, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_node_prev", "SELECT id, parent, word, usage, count FROM nodes"\
				" WHERE brain = $1 AND parent = $2 AND id < $3"\
				" ORDER BY id DESC LIMIT 1", 3, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_node_next", "SELECT id, parent, word, usage, count FROM nodes"\
				" WHERE brain = $1 AND parent = $2 AND id > $3"\
				" ORDER BY id LIMIT 1", 3, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_node_last", "SELECT id, parent, word, usage, count FROM nodes"\
				" WHERE brain = $1 AND parent = $2"\
				" ORDER BY id DESC LIMIT 1", 2, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = PQprepare(conn, "model_brain_words", "SELECT id, ROW_NUMBER() OVER (ORDER BY id) - 1, word "\
				" FROM words WHERE id IN (SELECT word FROM nodes WHERE brain=$1) ORDER BY word", 1, NULL);
			if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail;
			PQclear(res);

			res = NULL;

			if(db_commit()) goto fail2;

fail:
			if (res != NULL) {
				log_error("db_connect", PQresultStatus(res), PQresultErrorMessage(res));
				PQclear(res);
fail2:
				PQfinish(conn);
				conn = NULL;
			}
		}
	}

	if (conn == NULL)
		return -EDB;

	return OK;
}
Ejemplo n.º 14
0
int F930007(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg)
{
    int ret = 0;
    int cnt=0;
    int msgid=0;
    T_t_msglist tMsgList;
    T_t_device tDevice;

    ST_CPACK aPack;
    ST_PACK *out_pack = &(aPack.pack);

    ResetNormalCPack(&aPack,0,1);
    SetCol(handle,0);
    SetCol(handle,F_VSVARSTR0,0);
    memset(&tMsgList,0,sizeof(tMsgList));
    memset(&tDevice,0,sizeof(tDevice));

    if(strlen(in_pack->sdate0)==0)
    {
        *pRetCode=E_DEVPHYID_NULL;
        goto L_RETU;
    }
    ret=get_devinfo_by_phyid(in_pack->sdate0,&tDevice);
    if(ret)
    {
        *pRetCode=ret;
        writelog(LOG_ERR,"get_devinfo_by_phyid err[%d]",ret);
        goto L_RETU;
    }
    AddXmlItemInt(tMsgList.reqdata, XML_KEY_DEV999_NO, tDevice.deviceno);		//机号
    AddXmlItemStr(tMsgList.reqdata, XML_KEY_DEV999_ID, tDevice.devphyid);		//注册号
    AddXmlItemInt(tMsgList.reqdata, XML_KEY_BAUDRATE, tDevice.baudrate);		//波特率
//	AddXmlItemStr(tMsgList.reqdata, XML_KEY_SYSPWD, tDevice.syspwd);			//系统员密码
//	AddXmlItemStr(tMsgList.reqdata, XML_KEY_ADMPWD,tDevice.admpwd);			//管理员密码
//	AddXmlItemInt(tMsgList.reqdata, XML_KEY_PWDONOFF,tDevice.pwdonoff);		//密码开关
    AddXmlItemStr(tMsgList.reqdata, XML_KEY_CARDSTR, "100");					//卡片结构
//	AddXmlItemInt(tMsgList.reqdata, XML_KEY_CARDUSENUM,tDevice.cardusenum);	//卡的最大使用次数\允许最大消费次数
//	AddXmlItemInt(tMsgList.reqdata, XML_KEY_MAXDEPOSIT, tDevice.maxdeposit);	//钱包最高存款限额
//	AddXmlItemInt(tMsgList.reqdata, XML_KEY_MINDEPOSIT, tDevice.mindeposit);		//钱包最低剩余款限额
//	AddXmlItemInt(tMsgList.reqdata, XML_KEY_RATION, tDevice.ration);				//定值收费方式使用的定值额\定值金额
//	AddXmlItemStr(tMsgList.reqdata, XML_KEY_PUSERNO, tDevice.puserno);			//钱包代码\钱包号
//	AddXmlItemInt(tMsgList.reqdata, XML_KEY_MAXTRADE, tDevice.maxtrade);		//每次交易最高额\大额消费限额
    AddXmlItemStr(tMsgList.reqdata, XML_KEY_VCARDSET, tDevice.cardset);		//终端机适用用户卡类别
//	AddXmlItemStr(tMsgList.reqdata, XML_KEY_FUNONOFF, tDevice.funonoff);			//收费机增强功能开关
//	AddXmlItemInt(tMsgList.reqdata, XML_KEY_FEETYPE, tDevice.feetype);			//收费方式

    tMsgList.deviceid = tDevice.deviceid;
    tMsgList.funcno = 930007;
    tMsgList.msglevel = 2;
    ret=AddMsgLst(&tMsgList);
    if(ret)
    {
        *pRetCode=ret;
        writelog(LOG_ERR,"AddMsgLst err[%d]",ret);
        goto L_RETU;
    }
    if(iRequest!=tMsgList.funcno)
        return 0;
    ret=db_commit();
    if(ret)
    {
        writelog(LOG_ERR,"db_commit ret[%d]",ret);
        *pRetCode=E_DB_COMMIT;
        goto  L_RETU;
    }
    msgid=tMsgList.msgid;
    des2src(out_pack->sdate0,in_pack->sdate0);
    for(cnt=0; (cnt<10)&&(tMsgList.errcode!=0); cnt++)
    {
        sleep(1);
        memset(&tMsgList,0,sizeof(tMsgList));
        ret=DB_t_msglist_read_by_msgid(msgid, &tMsgList);
        if(ret)
        {
            writelog(LOG_ERR,"DB_t_msglist_read_by_msgid err[%d]",ret);
            *pRetCode=E_DB_MSGLIST_R;
            goto L_RETU;
        }
    }
    switch(tMsgList.errcode)
    {
    case 0:		//成功
        des2src(out_pack->vsvarstr0,"成功");
        break;
    case 9999:		//交易未处理
        des2src(out_pack->vsvarstr0,"前置机无应答");
        break;
    default:			//交易已经处理,但结果是失败
        des2src(out_pack->vsvarstr0,tMsgList.errmsg);
        break;
    }
    PutRow(handle,out_pack,pRetCode,szMsg);
    return 0;
L_RETU:
    return  -1;
}
Ejemplo n.º 15
0
static int TestTrans(TRUSERID *handle,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret=0;
	ST_CPACK aPack;
	ST_PACK *outPack = &(aPack.pack);
	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_LVOL0,F_LVOL1,F_LVOL2,F_LVOL8,F_LVOL10,F_LVOL11,F_LVOL12,F_SDATE0,F_SPHONE3,F_SADDR,F_LSAFE_LEVEL2,
		F_SDATE3,F_STIME3,F_SEMP,F_LWITHDRAW_FLAG,F_LSERIAL1,F_VSMESS,0);
	CAccTrans *pAccTrans=CAccTrans::getInstance();
	TRANS& trans=pAccTrans->trans;
	trans.transcode=TC_CARD2CARD;
	des2src(trans.opercode,rPack->semp);
	trans.termid=rPack->lwithdraw_flag;
	ret=pAccTrans->InitTrans();
	if(ret)
		return ret;	
	if(rPack->lvol0<1)
	{
		ERRTIP("请输入付款方卡号");
		return E_COMMON_ERR;
	}
	if(rPack->lvol2<1)
	{
		ERRTIP("请输入收款方卡号");
		return E_COMMON_ERR;
	}
	if(rPack->lvol1<0)
	{
		ERRTIP("请输入转账金额");
		return E_COMMON_ERR;
	}
	T_t_card tInCard;
	memset(&tInCard,0,sizeof(tInCard));

	T_t_account tInAccount;
	memset(&tInAccount,0,sizeof(tInAccount));

	pAccTrans->trans.cardno=rPack->lvol2;
	ret=pAccTrans->CheckAcc(&tInCard,&tInAccount);
	if(ret)
	{
		char sErrMsg[256];
		strcpy(sErrMsg,"收款方卡账户状态错误:");
		strcat(sErrMsg,pAccTrans->GetErrTip().c_str());
		ERRTIP(sErrMsg);
		return ret;
	}
	T_t_card  tOutCard;
	memset(&tOutCard,0,sizeof(tOutCard));

	T_t_account tOutAccount;
	memset(&tOutAccount,0,sizeof(tOutAccount));

	pAccTrans->trans.cardno=rPack->lvol0;

	ret=pAccTrans->CheckAcc(&tOutCard,&tOutAccount);
	if(ret)
	{
		char sErrMsg[256];
		strcpy(sErrMsg,"付款方卡账户状态错误:");
		strcat(sErrMsg,pAccTrans->GetErrTip().c_str());
		ERRTIP(sErrMsg);
		return ret;
	}
	double dInCardAftBal=(rPack->lvol1+rPack->lsafe_level)/100.0;
	trans.cardflag=0;
	trans.usecardflag=0;	
	trans.purseno=PURSE_NO_ONE;
	trans.paycnt=rPack->lvol6+1;
	des2src(trans.cardphyid,rPack->sstation1);

	trans.inputamt= D4U5(rPack->lvol1/100.0);	
	trans.unusedamt = trans.inputamt;
	trans.cardbefbal=rPack->lvol7/100.0;
	trans.cardaftbal=trans.cardbefbal - trans.inputamt;
	if(amtcmp(trans.inputamt,trans.cardbefbal)>0)
	{
		return ERRINFO(E_CARD_BALANCE_SHORTAGE,trans.cardbefbal);
	}	
	//检查收款方账户余额是否超过最大值
	double CardMaxBal=0;
	ret=GetPurseMaxBal(PURSE_NO_ONE,CardMaxBal);
	if(ret)
		return ret;
	if(amtcmp(dInCardAftBal,CardMaxBal)>=0)
	{
		return ERRINFO(E_AMT_EXCEED_MAX,CardMaxBal);
	}
		// 保持第三方账号
	T_t_transdtl transdtl;
	memset(&transdtl,0,sizeof(transdtl));
	transdtl.exttype = 0;
	sprintf(transdtl.voucherno,"%d",tInCard.cardno);
	transdtl.exttype=EXTTYPE_OPPSNO;
	GetStuempnoByCustid(tInCard.custid,transdtl.extdata);
	sprintf(transdtl.remark,"向(%s)转入",tInAccount.accname);
	ret = pAccTrans->GenTransdtl(&transdtl,DTLSTATUS_INIT);
	if(ret)
	{
		writelog(LOG_ERR,"GenTransdtl ret=%d",ret);
		return ret;
	}
	ret=db_commit();
	if(ret)
	{
		return ret;
	}	
	//trans.cardaftbal=trans.cardbefbal;
	strcpy(pAccTrans->trans.draccno,tOutAccount.accno);
	strcpy(pAccTrans->trans.craccno,tInAccount.accno);
	ret=pAccTrans->doTrans();
	if(ret)
	{
		writelog(LOG_ERR,"doTrans err=%d",ret);
		return ret;
	}
	ret=pAccTrans->doTransEnd();
	if(ret)
	{
		writelog(LOG_ERR,"doTransEnd err=%d",ret);
		return ret;
	}
	if(amtcmp(trans.cardaftbal,transdtl.cardaftbal)!=0)
	{
		ERRTIP("卡余额计算有误");
		return E_COMMON_ERR;
	}
	ret=db_rollback();
	if(ret)
	{
		writelog(LOG_ERR,"db_rollback err");
		return ret;
	}
	// 输出参数
	outPack->lvol0=tOutCard.cardno;
	outPack->lvol1=D4U5(trans.inputamt*100,0);
	outPack->lvol8=D4U5(transdtl.cardaftbal*100,0);
	outPack->lvol2=tInCard.cardno;
	outPack->lsafe_level2=D4U5(dInCardAftBal*100,0);
	des2src(outPack->sdate3,trans.accdate);
	des2src(outPack->stime3,trans.acctime);
	des2src(outPack->semp,trans.opercode);
	outPack->lwithdraw_flag=trans.termid;
	outPack->lserial1=trans.termseqno;
	des2src(outPack->sphone3,trans.refno);	
    des2src(outPack->saddr,trans.cardpwd);	//mac
    sprintf(trans.remark,"%s卡余额%.2lf元",pAccTrans->remark.c_str(),pAccTrans->trans.cardaftbal);
    des2src(outPack->vsmess,trans.remark);
	PutRow(handle,outPack,pRetCode,szMsg);
	return 0;
}
Ejemplo n.º 16
0
int process(char *buf) {
unsigned char *p=buf; int ok;
//printf("P:{%s}\n",buf);
if (strncmp(buf,".connect",7)==0) {
    p=buf+7; while(*p && *p<=32) p++;
    fprintf(stderr," ...connecting to <%s>\n",p);
    ok = db_connect_string(db,p);
    if (ok) fprintf(stderr,"+connected\n");
      else fprintf(stderr,"-err: %s\n",db->error);
    return 1;
    }
if (p[0]=='@') { // process file
    p++;
    printf("try run <%s>\n",p);
    FILE *f = fopen(p,"rt");
    if (!f) { fprintf(stderr,"fail open script %s\n",p); return 1;}
       process_file(f);
    fclose(f);
    return 1; // OK
    }
if (lcmp(&p,".echo")) {
    fprintf(stderr,"%s\n",p);
    return 1;
    }
if (lcmp(&p,".mode")) {
      unsigned char *m=get_word(&p);
      if ( lcmp(&m,"csv"))  { mode=1; fprintf(stderr,"+mode  csv now\n"); return 1;}
      if ( lcmp(&m,"text")) { mode=0; fprintf(stderr,"+mode  text now\n"); return 1;}
      if ( lcmp(&m,"json")) { mode=2; fprintf(stderr,"+mode  json now\n"); return 1;}
      fprintf(stderr,"ERR: mode %s unknown\n",m);
      return 2;
      }
if (lcmp(&p,".http.Auth")) { // set auth string
      vdb_http_auth_set(p);
      return 1;
      }
if (lcmp(&p,".http")) { // start http server
      int code = vdb_http_start();
      fprintf(stderr,"+server started code=%d\n",code);
      return 1;
      //vdb_http_process();
      }
if (lcmp(&p,"url")) {
      char *u = get_word(&p); // rest is SQL
      http_addSQL(u,p);
      fprintf(stderr,"url %s added to map\n",u);
      return 1;
    }
if (strcmp(buf,".help")==0) { prn_help(); return 1;}
if (strcmp(buf,".reconnects")==0) { do_reconnects(0); return 1;}
if (strcmp(buf,".stressFetch")==0) { do_stress_fetch("select* from test"); return 1;}
if (strcmp(buf,".stress")==0) { do_reconnects("select * from test"); return 1;}
if (strcmp(buf,".btest")==0) { do_binds("select * from dual where dummy = :txt"); return 1;}
if (lcmp(&p,".output")) {
    output = fopen(p,"wt");
    if (!output) { fprintf(stderr,"cant open file %s",p);}
    return 1;
    }
//if (strcmp(buf,".btest")==0) { do_binds("select * from email where sender = :txt"); return 1;}
if (strcmp(buf,".quit")==0) exit(0);
if (strcmp(buf,".rollback")==0) {
     printf("rollback code = %d\n",db_rollback(db)); return 1;
    }
if (strcmp(buf,".commit")==0) {
     printf("commit code = %d\n",db_commit(db)); return 1;
    }
if (strncmp(buf,".compile",8)==0) {
    char *sql = buf+8;
    fprintf(stderr," ...compiling sql <%s>\n",sql);
    if (!db_compile(db,sql)) fprintf(stderr,"-err compile: %s\n",db->error);
      else fprintf(stderr,"+ok compiled\n");
    return 1;
    }
if (lcmp(&p,".import")) {
     char *file = get_word(&p);
     char *tbl  = get_word(&p);
     if (mode==0) return vdb_upload(db,file,tbl,get_col);
        else return vdb_upload(db,file,tbl,get_csv_col);

    }
if (strncmp(buf,".sql",4)==0) {
    char *sql = buf+4; int ok;
    fprintf(stderr," ...compile&exec sql <%s>\n",sql);
    ok = db_compile(db,sql) && db_exec(db);
    if (!ok) fprintf(stderr,"-err : %s\n",db->error);
      else fprintf(stderr,"+ok execed\n");
    return 1;
    }
if (strncmp(buf,".desc",5)==0) {
    char *sql = buf+5; int ok,i;
    fprintf(stderr," ...describe sql <%s>\n",sql);
    ok = db_compile(db,sql) && db_open(db);
    if (!ok) { fprintf(stderr,"-err : %s\n",db->error); return 1; }
    for(i=0;i<db->out.count;i++) {
        db_col *c = db->out.cols+i;
        printf(" %2d. NAME:%-20s TYP:%d LEN:%d DBTYPE:%d\n",i,c->name,c->type,c->len,c->dbtype);
        }
    fprintf(stderr,"+ok %d columns\n",i);
    return 1;
    }
if (strncmp(buf,"select",6)==0) {
    int row=0;
    //fprintf(stderr," ...selecting sql <%s>\n",buf);
    if (!db_select(db,buf)) { fprintf(stderr,"-err: %s\n",db->error); return 1;}
   // fprintf(stderr,"begin output=%p mode=%d\n",output,mode);
    row = dump_dataset( output, db, mode);
    if (output) { fclose(output); output=0; }
    fprintf(stderr,"+%d rows selected\n",row);
    return 1;
    }
fprintf(stderr,"-command unknown '%s'\n",buf);
return 1;
}
Ejemplo n.º 17
0
int CallBDFunc(int fno,TRUSERID *handle,ST_CPACK *rpack,ST_PACK *pArrays,int *iRetCode, char *szMsg)
{
   int r=0;
   int rtn=0;
   int sendtype=0;
   char param[101]="";
#ifdef _DEBUG1
CMemoryState cm1, cm2, cm3;
#endif
   APPFUNC pFunc = g_XBDefines[fno].pFunc;

#ifdef _DEBUG1
	cm1.Checkpoint();
#endif
	*iRetCode=0;
	*szMsg=0;
	g_pArrays=pArrays;
	//判断是否是结帐时刻,如果是则等待处理
	sendtype=rpack->head.RequestType;
	switch(sendtype)
       {
       	case 95:
		case 93:
#ifdef _DEBUG_CPACK
			rtn=SaveCPackData(rpack);
			if(rtn)
			{
				//writelog(LOG_ERR,"SaveCpackData err ");
				strcpy(szMsg,"写流水日志表错误");
				ERR_DEAL( szMsg,rtn);
				break;
			}
#endif
			
			rtn = (*pFunc)(handle,rpack->head.RequestType,&rpack->pack,iRetCode,szMsg);
#ifdef _DEBUG1
			cm2.Checkpoint();
			if (cm3.Difference(cm1, cm2))
			{
			      BCCMsgLogOut(14444,"在执行功能号:%u时候,经检查,内存出现错误!",rpack->head.RequestType);
			      g_LogFile.WriteLogEx(14444,"在执行功能号:%u时候,经检查,内存出现错误!",rpack->head.RequestType);
					cm3.DumpStatistics();
			}
#endif 
			break;
		default:
		 	rtn=GetParameter(GLOBE_FLAG_BALANCE,param);
			if(rtn)
			{
				*iRetCode=rtn;
				break;
			}
			else if(strncmp(param,"0",1)!=0)
			{
				rtn=E_DAYEND_STATUS;
				*iRetCode=rtn;
				break;
			}
			rtn=SaveCPackData(rpack);
			if(rtn)
			{
				//writelog(LOG_ERR,"SaveCpackData err ");
				strcpy(szMsg,"写流水日志表错误");
				ERR_DEAL( szMsg,rtn);
				break;
			}
			rtn = (*pFunc)(handle,rpack->head.RequestType,&rpack->pack,iRetCode,szMsg);
#ifdef _DEBUG1
			cm2.Checkpoint();
			if (cm3.Difference(cm1, cm2))
			{
			      BCCMsgLogOut(14444,"在执行功能号:%u时候,经检查,内存出现错误!",rpack->head.RequestType);
			      g_LogFile.WriteLogEx(14444,"在执行功能号:%u时候,经检查,内存出现错误!",rpack->head.RequestType);
					cm3.DumpStatistics();
			}
#endif 
	              break;
       }
	
	if(rtn)
	{
	   	char sErrMsg[101]="";
		char sRetMsg[256]="";
		if(*szMsg)
			snprintf(sRetMsg,256," %s",szMsg);
		if(*iRetCode==0)
		 	 *iRetCode=rtn;
		r=get_errcode_msg(*iRetCode, sErrMsg);
		db_rollback();
		snprintf(szMsg,256,"%s%s\n%s",sErrMsg,sRetMsg,g_sqlmsg);
		writelog(LOG_ERR,"Func[%d]ecode[%d]msg[%s]",rpack->head.RequestType,*iRetCode,szMsg);
		ERR_DEAL(szMsg,*iRetCode);
		if(r)
		{
			AnswerData(handle,*iRetCode,szMsg);
			db_disconnect();
			writelog(LOG_ERR,"数据库错误,系统退出");
			exit(1);
		}
	}
	else
	{
		if(strncmp(rpack->pack.scust_limit,"test",4)==0)
			db_rollback();
		else
		{
			r=db_commit();
			if(r)
			{
				*iRetCode=E_DB_COMMIT;
				strcpy(szMsg,"数据库事务提交失败");
				writelog(LOG_ERR,"Func[%d]Msg[%s]",rpack->head.RequestType,szMsg);
				db_rollback();
				ERR_DEAL( szMsg,*iRetCode);
			}
		}
	}

   	return(rtn);
}
Ejemplo n.º 18
0
int F930064(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg)
{
	int ret = 0;
	int cnt=0;
	int mesid=0;
	char dev999_no[20]="";
     	T_t_tif_meslist tMesList;
	T_t_pif_device tDevice;
	memset(&tDevice,0,sizeof tDevice);

	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);	
	SetCol(handle,F_SDATE0,F_SDATE2,F_SDATE3,F_LVOL3,F_VSVARSTR0,0);
	memset(&tMesList,0,sizeof(tMesList));

	if(strlen(in_pack->sdate0)==0)
	{
		*pRetCode=E_DEVPHYID_NULL;
		goto L_RETU;
	}

	AddXmlItemInt(tMesList.incontent, XML_KEY_MAXTRADE, in_pack->lvol4);

	if((ret = get_devinfo_by_phyid(in_pack->sdate0,&tDevice)))
	{
		*pRetCode = ret;
		goto L_RETU;
	}
	tMesList.devid = tDevice.device_id;
	tMesList.funid = 930064;
	tMesList.level = 2;
	ret=AddMsgLst(&tMesList);
	if(ret)
	{
		*pRetCode=ret;
		writelog(LOG_ERR,"AddMsgLst err[%d]",ret);
		goto L_RETU;
	}
	if(iRequest!=tMesList.funid)
		return 0;	
	ret=db_commit();
	if(ret)
	{
		writelog(LOG_ERR,"db_commit ret[%d]",ret);
		*pRetCode=E_DB_COMMIT;
		goto  L_RETU;
	}
	mesid=tMesList.mesid;
	des2src(out_pack->sdate0,in_pack->sdate0);
	for(cnt=0;(cnt<10)&&(tMesList.ecode!=0);cnt++)
	{
		sleep(1);
		memset(&tMesList,0,sizeof(tMesList));
		ret=DB_t_tif_meslist_read_by_mesid(mesid, &tMesList);
		if(ret)
		{
			writelog(LOG_ERR,"DB_t_tif_meslist_read_by_mesid err[%d]",ret);
			*pRetCode=E_DB_MESLIST_R;
			goto L_RETU;
		}
	}
	switch(tMesList.ecode)
	{
		case 0:		//成功
			des2src(out_pack->vsvarstr0,"成功");

			ret=GetXmlValue(out_pack->sdate0,sizeof(out_pack->sdate0),XML_KEY_DEVPHY999_NO, tMesList.outcontent);
			if(ret)
			{
				*pRetCode=ret;
				goto L_RETU;
			}			
			ret=GetXmlValue(dev999_no,sizeof(dev999_no),XML_KEY_DEV999_NO, tMesList.outcontent);
			if(ret)
			{
				*pRetCode=ret;
				goto L_RETU;
			}	
			out_pack->lvol3=atoi(dev999_no);
			ret=GetXmlValue(out_pack->sdate2,sizeof(out_pack->sdate2),XML_KEY_DEV999_ID, tMesList.outcontent);
			if(ret)
			{
				*pRetCode=ret;
				goto L_RETU;
			}			
			ret=GetXmlValue(out_pack->semp,sizeof(out_pack->semp),XML_KEY_DEVTYPE, tMesList.outcontent);
			if(ret)
			{
				*pRetCode=ret;
				goto L_RETU;
			}						
			ret=GetXmlValue(out_pack->sdate3,sizeof(out_pack->sdate3),XML_KEY_DEVVERSION, tMesList.outcontent);
			if(ret)
			{
				*pRetCode=ret;
				goto L_RETU;
			}						
			break;
		case 9999:		//交易未处理
			des2src(out_pack->vsvarstr0,"前置机无应答");
			break;
		default:			//交易已经处理,但结果是失败
			des2src(out_pack->vsvarstr0,tMesList.emsg);				
			break;
	}	
	
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return  -1;	
}
Ejemplo n.º 19
0
int F950041(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg)
{
	int ret;
	T_t_pif_device tDevice;
	T_t_cif_shop_pos tShopPos;
	T_t_cif_shop tShop;
	T_t_tif_meslist tMsg;
	T_t_pif_feetype tFeeType;
	int rate = 0;
	int retries = 0;
	int msgid;
	unsigned char buf[32] = "";
	char cardlist[100] = "";
	int rows = 0;
	int i,j;

	memset(&tDevice,0,sizeof tDevice);
	memset(&tFeeType,0,sizeof tFeeType);
	
	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);
	memset(&aPack,0,sizeof aPack);

	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_VSVARSTR0,F_VSMESS,0);
	
	if(rPack->lcert_code < 1)
	{
		*pRetCode = E_DEVICE_NOT_EXIST;
	}
	else if((ret = DB_t_pif_device_read_by_device_id(rPack->lcert_code,&tDevice)))
	{
		if(DB_NOTFOUND == ret)
			*pRetCode = E_DB_DEVICE_N;
		else
			*pRetCode = E_DB_DEVICE_R;

	}
	else if(tDevice.state_id == DEVISTAT_LOGOUT)
	{
		*pRetCode = E_DEVICE_NOT_EXIST;
	}
	else if((ret = DB_t_cif_shop_pos_open_select_by_c0_and_device_id(rPack->lcert_code)))
	{
		*pRetCode = E_DB_SHOP_POS_R;
	}
	else
	{
		while(1)
		{
			memset(&tShopPos,0,sizeof tShopPos);
			memset(&tShop,0,sizeof tShop);
			if((ret = DB_t_cif_shop_pos_fetch_select_by_c0(&tShopPos)))
			{
				if(ret == DB_NOTFOUND)
				{
					writelog(LOG_DEBUG,"shop doesn't find [%d]!");
					*pRetCode  = 0;
				}
				else
					*pRetCode = E_DB_SHOP_POS_R;
				break;
			}
			writelog(LOG_DEBUG,"find shop [%d]",tShopPos.shop_id);
			if((ret = DB_t_cif_shop_read_by_shop_id(tShopPos.shop_id,&tShop)))
			{
				*pRetCode = ret;
				break;
			}
			if('1' == tShop.is_leaf[0] && '1' == tShop.is_getfee[0]
				&& amtcmp(tShop.ratio,0.00)>0 )
			{
				writelog(LOG_DEBUG,"shop rate [%.02f]",tShop.ratio);
				int newrate = D2I(tShop.ratio * 100);
				if(newrate > rate)
					rate = newrate;
			}
		}
		
	}
	if(*pRetCode)
		return -1;
	
	ret = DB_t_pif_feetype_open_select_by_cur1();
	if(ret)
	{
		if(DB_NOTFOUND == ret)
			*pRetCode = E_DB_FEETYPE_N;
		else
			*pRetCode = E_DB_FEETYPE_R;
		return -1;
	}
	memset(buf,0,sizeof buf);
	while(1)
	{
		memset(&tFeeType,0,sizeof &tFeeType);
		ret = DB_t_pif_feetype_fetch_select_by_cur1(&tFeeType);
		if(ret)
		{
			if(DB_NOTFOUND == ret)
			{
				if(rows > 0)
					break;
				*pRetCode = E_DB_FEETYPE_N;
			}
			else
				*pRetCode = E_DB_FEETYPE_R;
		}
		rows++;
		if(tFeeType.fee_type < 0 || tFeeType.fee_type > 255
			|| tFeeType.is_outfee[0] != '1' )
			continue;
		writelog(LOG_DEBUG,"fee[%s][%d][%c]",tFeeType.fee_name,tFeeType.fee_type
			,tFeeType.is_outfee[0]);
		_SET_BIT(buf,tFeeType.fee_type-1);
		
	}
	writelog(LOG_DEBUG,"bit length %d",BIT_LENGTH);
	memset(&tMsg,0,sizeof tMsg);
	tMsg.funid = 950041;
	tMsg.level = 1;
	tMsg.devid = tDevice.device_id;
	for(i = 0,j = 0;i < sizeof buf;++i)
	{
		j += sprintf(cardlist+j,"%02x",buf[i]);
	}
	AddXmlItemInt(tMsg.incontent,XML_KEY_FEE,rate);
	AddXmlItemStr(tMsg.incontent,XML_KEY_CARDRIGHTTYPE,cardlist);
	tMsg.max_send_cnt = 5;
	if((ret = AddMsgLst(&tMsg)))
	{
		*pRetCode = ret;
	}
	else
	{
		if(db_commit())
		{
			*pRetCode = E_DB_COMMIT;
			return -1;
		}
		retries = 10;
		msgid = tMsg.mesid;
		for(retries=0;(retries<10)&&(tMsg.ecode!=0);retries++)
		{
			memset(&tMsg,0,sizeof tMsg);
			ret = DB_t_tif_meslist_read_by_mesid(msgid,&tMsg);
			if(ret)
			{
				strcpy(out_pack->vsvarstr0,"读取指令失败");
				*pRetCode=E_DB_MESLIST_R;
				strcpy(szMsg,"读取指令失败");
				return -1;
			}
			// 等待1秒
			sleep(1);
		}
		switch(tMsg.ecode)
		{
			case 0:		//成功
				des2src(out_pack->vsmess,"成功");
				strcpy(szMsg,"成功");
				break;
			case 9999:		//交易未处理
				des2src(out_pack->vsmess,"前置机无应答");
				strcpy(szMsg,"前置机无应答");
				goto LRet;
			default:			//交易已经处理,但结果是失败
				des2src(out_pack->vsmess,tMsg.emsg);				
				goto LRet;
		}	

		PutRow(handle,out_pack,pRetCode,szMsg);
		AnswerData(handle,*pRetCode,szMsg);
		return 0;
		
	}
LRet:
	return -1;
}
Ejemplo n.º 20
0
int F930056(TRUSERID *handle,int iRequest,ST_PACK *in_pack,int *pRetCode,char *szMsg)
{	
	int ret = 0;
	int cnt=0;
	int mesid=0;
     	T_t_tif_meslist tMesList;

	ST_CPACK aPack;
	ST_PACK *out_pack = &(aPack.pack);

	ResetNormalCPack(&aPack,0,1);
	SetCol(handle,0);
	SetCol(handle,F_VSVARSTR0,0);
	memset(&tMesList,0,sizeof(tMesList));

	AddXmlItemInt(tMesList.incontent,XML_KEY_BTTIME, in_pack->lvol4);

	tMesList.funid = 930056;
	tMesList.level = 2;
	ret=AddMsgLst(&tMesList);
	if(ret)
	{
		*pRetCode=ret;
		writelog(LOG_ERR,"AddMsgLst err[%d]",ret);
		goto L_RETU;
	}
	if(iRequest!=tMesList.funid)
		return 0;	
	ret=db_commit();
	if(ret)
	{
		writelog(LOG_ERR,"db_commit ret[%d]",ret);
		*pRetCode=E_DB_COMMIT;
		goto  L_RETU;
	}
	mesid=tMesList.mesid;
	des2src(out_pack->sdate0,in_pack->sdate0);
	for(cnt=0;(cnt<10)&&(tMesList.ecode!=0);cnt++)
	{
		sleep(1);
		memset(&tMesList,0,sizeof(tMesList));
		ret=DB_t_tif_meslist_read_by_mesid(mesid, &tMesList);
		if(ret)
		{
			writelog(LOG_ERR,"DB_t_tif_meslist_read_by_mesid err[%d]",ret);
			*pRetCode=E_DB_MESLIST_R;
			goto L_RETU;
		}
	}
	switch(tMesList.ecode)
	{
		case 0:		//成功
			des2src(out_pack->vsvarstr0,"成功");
			break;
		case 9999:		//交易未处理
			des2src(out_pack->vsvarstr0,"前置机无应答");
			break;
		default:			//交易已经处理,但结果是失败
			des2src(out_pack->vsvarstr0,tMesList.emsg);				
			break;
	}	
	PutRow(handle,out_pack,pRetCode,szMsg);
	return 0;
L_RETU:
	return  -1;	
}