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

📄 hfcjzc.cpp

📁 170话费催交系统
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	
	//读信号灯在sysinit的时候已经进行
	//for(i=0;i<MAXDEVS;i++) {
	//	itoa(i+1,ls_i,10);
	//	strcpy(signlight[i].app_id,(char *)ReadSemaphoneFile(ls_i,appid));
	//}
	
	//i=0;
	while(1) {
		//Sleep(0);
		if(stopdata==STOPTRUE){
			//AfxMessageBox("主控程序终止");
			break;
		}
		if((maincounts > 0)&&(Cmpcjarg(&cjarg))){	//如果缓冲区里有数据且到了催缴时间即开始催缴
			//取得DLL函数指针应在初使化时做
			//VERIFY(pReadxhd=(READXHDPROC*)::GetProcAddress(lpxhddll,"ReadSemaphoneFile"));
			//itoa(i+1,ls_i,10);
			//strcpy(signlight[i].app_id,(char *)ReadSemaphoneFile(ls_i,appid));
			if(strcmp(signlight[i].app_id,cjappid)==0) {
				//strcpy(signlight[i].chn_value,(char *)ReadSemaphoneFile(ls_i,chnvalue));
				if(atoi(signlight[i].chn_value)==CHDEVIDLE) {
					//进行拨号工作
					/*while(dxinfo[i].chdialcount<MAXDIALCOUNT){
						if(yin_seize(i) != 1)
							break;
						sleep(30);
						strcpy(signlight[i].chn_value,(char *)ReadSemaphoneFile(ls_i,chnvalue));
						if(atoi(signlight[i].chn_value)==CHDEVWORK)
							break;
						dxinfo[i].chdialcount++;
						idle(0);
					}*/
					yin_seize(i);
					Sleep(cjarg.bohao_time);	//拨了一个号码后,稍停顿,然后再拨下一个号码
				}
				/*else if(atoi(signlight[i].chn_value)==CHDEVUNOPEN) {
					//重新打开一次
				}*/
				else
				{
					//Sleep(0);
				}
			}
			if(i>=MAXDEVS-1)
				i=0;
			else
				i++;
		}
		else{
			//SysPrintf("主缓冲区无数据");
			Sleep(1000);
		}
	}
	return(0);
}

/************************************************************************
*     名称:BOOL Cmpcjarg(CJ_ARG* lpcjarg)
*     功能:判定是否到了催缴时间
************************************************************************/
BOOL Cmpcjarg(CJ_ARG* lpcjarg)
{
	char ls_time[TIME_LENGTH];
	char* ls_timea;
	char* ls_timeb;
	int li_year;
	int li_month;
	int li_day;
	int li_hour;
	int li_minute;
	int li_second;

	GetTime(ls_time);
	ls_timea=ls_time;
	ls_timeb=ls_timea+4;
	*ls_timeb='\0';
	ls_timeb++;
	li_year=atoi(ls_timea);
	ls_timea=ls_timeb;
	ls_timeb=ls_timea+2;
	*ls_timeb='\0';
	ls_timeb++;
	li_month=atoi(ls_timea);
	ls_timea=ls_timeb;
	ls_timeb=ls_timea+2;
	*ls_timeb='\0';
	ls_timeb++;
	li_day=atoi(ls_timea);
	ls_timea=ls_timeb;
	ls_timeb=ls_timea+2;
	*ls_timeb='\0';
	ls_timeb++;
	li_hour=atoi(ls_timea);
	ls_timea=ls_timeb;
	ls_timeb=ls_timea+2;
	*ls_timeb='\0';
	ls_timeb++;
	li_minute=atoi(ls_timea);
	ls_timea=ls_timeb;
	ls_timeb=ls_timea+2;
	*ls_timeb='\0';
	li_second=atoi(ls_timea);

	if(lpcjarg->cjtime_one == 1) {
		if((li_month>=lpcjarg->cjtime[0].start_month)&&(li_month<=lpcjarg->cjtime[0].end_month)&&
			(li_day>=lpcjarg->cjtime[0].start_day)&&(li_day<=lpcjarg->cjtime[0].end_day)&&
			 (((li_hour>lpcjarg->cjtime[0].start_hour)&&(li_hour<lpcjarg->cjtime[0].end_hour))||
			  ((li_hour==lpcjarg->cjtime[0].start_hour)&&(li_minute>=lpcjarg->cjtime[0].start_minute))||
			   ((li_hour==lpcjarg->cjtime[0].end_hour)&&(li_minute<=lpcjarg->cjtime[0].end_minute)))) {
				return TRUE;
		}
	}
	if(lpcjarg->cjtime_two == 1){
		if((li_month>=lpcjarg->cjtime[1].start_month)&&(li_month<=lpcjarg->cjtime[1].end_month)&&
			(li_day>=lpcjarg->cjtime[1].start_day)&&(li_day<=lpcjarg->cjtime[1].end_day)&&
			 (((li_hour>lpcjarg->cjtime[1].start_hour)&&(li_hour<lpcjarg->cjtime[1].end_hour))||
			  ((li_hour==lpcjarg->cjtime[1].start_hour)&&(li_minute>=lpcjarg->cjtime[1].start_minute))||
			   ((li_hour==lpcjarg->cjtime[1].end_hour)&&(li_minute<=lpcjarg->cjtime[1].end_minute)))) {
				return TRUE;
		}
	}
	if(lpcjarg->cjtime_three == 1){
		if((li_month>=lpcjarg->cjtime[2].start_month)&&(li_month<=lpcjarg->cjtime[2].end_month)&&
			(li_day>=lpcjarg->cjtime[2].start_day)&&(li_day<=lpcjarg->cjtime[2].end_day)&&
			 (((li_hour>lpcjarg->cjtime[2].start_hour)&&(li_hour<lpcjarg->cjtime[2].end_hour))||
			  ((li_hour==lpcjarg->cjtime[2].start_hour)&&(li_minute>=lpcjarg->cjtime[2].start_minute))||
			   ((li_hour==lpcjarg->cjtime[2].end_hour)&&(li_minute<=lpcjarg->cjtime[2].end_minute)))) {
				return TRUE;
		}
	}
	/*if((lpcjarg->cjtime_one != 1)&&(lpcjarg->cjtime_one != 1)&&(lpcjarg->cjtime_one != 1)) {
		return TRUE;
	}*/
	return FALSE;
}

/*************************************************************************
 *			Fuction    : int yin_seize(int i)
 *			Description: set abit off (j<MAXCHAN) prepare to dialout
 **************************************************************************/
int yin_seize(int i)
{
	long tsbits;
	int arcv,brcv,crcv,drcv,axmt,bxmt,cxmt,dxmt;
	int chan_ok=0;
	char ls_i[10];

	if((tsbits=ATDT_TSSGBIT(dxinfo[i].dtdev))==AT_FAILURE){
		TRACE("ATDT_TSSGBIT() error");
		return -1;
	}
	arcv=(tsbits & DTSG_RCVA)?1:0;
	brcv=(tsbits & DTSG_RCVB)?1:0;
	crcv=(tsbits & DTSG_RCVC)?1:0;
	drcv=(tsbits & DTSG_RCVD)?1:0;
	axmt=(tsbits & DTSG_XMTA)?1:0;
	bxmt=(tsbits & DTSG_XMTB)?1:0;
	cxmt=(tsbits & DTSG_XMTC)?1:0;
	dxmt=(tsbits & DTSG_XMTD)?1:0;

	chan_ok=(arcv==1)&&(brcv==0)&&(crcv==1)&&(drcv==1);
	if(!chan_ok){
		TRACE("%s: RX(%d%d%d%d) ****** CPE Not Ready ***** %2d",
			dxinfo[i].dtdevname,arcv,brcv,crcv,drcv,i);
		chan_init(i);
		return 0;
	}

	chan_ok=(axmt==1)&&(bxmt==0)&&(cxmt==1)&&(dxmt==1);
	if(!chan_ok){
		TRACE("%s: TX(%d%d%d%d) ****** CO Not Ready ***** %2d",
			dxinfo[i].dtdevname,axmt,bxmt,cxmt,dxmt,i);
		chan_init(i);
		return 0;
	}
	
	if(dt_settssig(dxinfo[i].dtdev,DTB_ABIT,DTA_SUBMSK)!=0){
		TRACE("%s: dt_settssig() error",dxinfo[i].dtdevname);
		return -1;
	}
	dxinfo[i].chdevzt=CHDEVZT_B;
	strcpy(dxinfo[i].chdevztmx,chdevztmx[1]);
	dxinfo[i].chtime=0;
	GetTime(teleinfo[i].qssj_time);
	//itoa(i+1,ls_i,10);
	itoa(CHDEVWORK,signlight[i].chn_value,10);
	//SetSemaphoneFile(ls_i,chnvalue,signlight[i].chn_value);
	//clr_output(i);
	//ChnPrintf(i+1,"_BEGIN",teleinfo[i].qssj_time);
	//ChnPrintf(i+1,"_STATE","摘机");
	init_count[i]=0;
	return 1;
}

/*************************************************************************
 *          Name: int chan_init(int i)
 *      Function: set dti device on hook
 *	    Parameter: channel cur_num
 *  Return value: 0, if successful
 *					 : -1, unsuccessful	 
 *************************************************************************/
int chan_init(int i)
{
	char ls_i[10];
	//int devzt;

	dxinfo[i].chdevzt=CHDEVZT_A;
	strcpy(dxinfo[i].chdevztmx,chdevztmx[0]);
	dxinfo[i].chtime=0;
	dxinfo[i].bksig=SIGA_1;
	dxinfo[i].ani_num=0;
	dxinfo[i].dnis_num=0;
	dxinfo[i].Sending=0; //(=0 for DNIS),(=1 for ANI)
	//dxinfo[i].chdialcount=0;
	dt_settssigsim(dxinfo[i].dtdev,DTB_AON|DTB_BOFF|DTB_CON|DTB_DON);
	//devzt=CHDEVIDLE;
	//itoa(devzt,signlight[i].chn_value,10);
	itoa(CHDEVIDLE,signlight[i].chn_value,10);
	//itoa(i+1,ls_i,10);
	//SetSemaphoneFile(ls_i,chnvalue,signlight[i].chn_value);
	clr_output(i);
	//ChnPrintf(i+1,"_STATE","空闲");
	return 0;
}

/************************************************************************
*     名称:UINT Cjwork(LPVOID pParam)
*     功能:催缴工作线程函数
************************************************************************/
UINT Cjwork(LPVOID pParam)
{
	long  evt_handle;
	long tmp_dev;
	long eventtype;
	int channel;

	while(1) {
		if(sr_waitevtEx(cjchdev, cjdevcounts, -1, &evt_handle)==-1){
			Sleep(30);
			TRACE("sr_waitevtEx error");
			continue;
		}

		tmp_dev = sr_getevtdev(evt_handle);
		eventtype = sr_getevttype(evt_handle);
		if((tmp_dev==cjchdev[0])&&(eventtype==USEREVT_KEYBOARD)){
            //AfxMessageBox("Stop the dialogic thread");
			break;
		}

		// Get the channel number from which the event was received.
		channel=0;
		while (channel < MAXDEVS) {
			if(dxinfo[channel].dtdev==tmp_dev) {
				break;
			}
			if(dxinfo[channel].chdev==tmp_dev) {
				break;
			}
			channel++;
		}

		if(channel >= MAXDEVS) 
			continue;

		if(Process(channel, evt_handle)!=0)
			break;
	}

    //结束时关闭所有通道
	end_prog();

	return(0);
}

/***************************************************************
 *	名称:int Process(int channel,unsigned long evt_handle)
 *	功能:催缴工作线程中调用到的处理函数
 **************************************************************/
int Process(int channel,unsigned long evt_handle)
{
	long eventtype;
	long *datap;
	DX_CST *cstp;
	long term;

	eventtype = sr_getevttype(evt_handle);
	dxinfo[channel].chtime=0;

	switch(eventtype){
	case DTEV_SIG: //event on DTI
		datap=(long*)sr_getevtdatap(evt_handle);
		if((*datap & DTMM_AON)==DTMM_AON){
			TRACE("%s: --- EVENT DATA: DTMM_AON",dxinfo[channel].dtdevname);
			//处理DTMM_AON事件(挂机,不处理)
		}
		if((*datap & DTMM_AOFF)==DTMM_AOFF){
			TRACE("%s: --- EVENT DATA: DTMM_AOFF",dxinfo[channel].dtdevname);
			//处理DTMM_AOFF事件(远端摘机,放催缴音)
			dxinfo[channel].chdevzt=CHDEVZT_E;
			//发送屏显
			strcpy(dxinfo[channel].chdevztmx,chdevztmx[4]);
			strcpy(dxinfo[channel].chdevcjjg,"催缴成功");
			//ChnPrintf(channel+1,"_STATE","用户接听");
			yin_playf(channel);
		}
		if((*datap & DTMM_BON)==DTMM_BON){
			TRACE("%s: --- EVENT DATA: DTMM_BON",dxinfo[channel].dtdevname);
			//处理DTMM_BON事件(交换机应答,发一个playtone)
			dxinfo[channel].chdevzt=CHDEVZT_C;
			strcpy(dxinfo[channel].chdevztmx,chdevztmx[2]);
			//应答前先从缓冲区中读一条数据,
			if(Readdata(channel) == -1){
				return(0);
			}
			//写屏显信息
			//ChnPrintf(channel+1,"_STATE","拨催缴号");
			//ChnPrintf(channel+1,"_TELE",teleinfo[channel].num);
			yin_mfc(channel);
		}
		if((*datap & DTMM_BOFF)==DTMM_BOFF){
			TRACE("%s: --- EVENT DATA: DTMM_BOFF",dxinfo[channel].dtdevname);
			//处理DTMM_BOFF事件(远端挂机)
			//播音完成前用户挂机产生此事件时,通道停止播放催缴音
			switch(dxinfo[channel].chdevzt){
			case CHDEVZT_E:
				if(dxinfo[channel].playflag==1){
					dx_stopch(dxinfo[channel].chdev,EV_ASYNC);
				}
				else{
					//ChnPrintf(channel+1,"_STATE","用户挂机");
					strcpy(dxinfo[channel].chdevztmx,chdevztmx[6]);
					yin_fwaon(channel);
				}
				break;
			case CHDEVZT_B:
			case CHDEVZT_C:
			case CHDEVZT_D:
				strcpy(dxinfo[channel].chdevztmx,chdevztmx[6]);
				//ChnPrintf(channel+1,"_STATE","用户挂机");
				yin_fwaon(channel);
				break;
			}
		}
		break;
	case TDX_CST:
		cstp=(DX_CST*)sr_getevtdatap(evt_handle);
		switch (cstp->cst_event){
		case DE_TONEON:
			TRACE("--- EVENT DATA: DE_TONEON");
			//处理 DE_TONEON事件(接收bksig,并处理)
			yin_getbksig(channel,evt_handle);
			if(dxinfo[channel].chdevzt==CHDEVZT_D){
				strcpy(dxinfo[channel].chdevztmx,chdevztmx[3]);
				//ChnPrintf(channel+1,"_STATE","振铃");
			}
			break;
		case DE_TONEOFF:
			TRACE("--- EVENT DATA: DE_TONEOFF");
			//处理 DE_TONEOFF事件(接收完成,发送下一个playtone)
			yin_mfc(channel);
			break;
		}
	case TDX_PLAY: /* Play ENDS*/
		switch(dxinfo[channel].chdevzt){
		case CHDEVZT_E:
			dxinfo[channel].playflag=0;
			term=ATDX_TERMMSK(dxinfo[channel].chdev);
			if(term & TM_USRSTOP)
				TRACE("%s: Play ended by TM_USRSTOP",dxinfo[channel].chdevname);
				//break;
			if(term & TM_MAXTIME)
				TRACE("%s: Play ended by TM_MAXTIME",dxinfo[channel].chdevname);
			if(term & TM_EOD)
				TRACE("%s: Play ended by TM_EOD",dxinfo[channel].chdevname);
			//发送屏显
			//ChnPrintf(channel+1,"_STATE","写数据库日志");
			strcpy(dxinfo[channel].chdevztmx,chdevztmx[5]);
			dxinfo[channel].chdevzt=CHDEVZT_F;
			GetTime(teleinfo[channel].zzsj_time);
			//ChnPrintf(channel+1,"_END",teleinfo[channel].zzsj_time);
			teleinfo[channel].cjcount++;
			//SysPrintf("teleinfo %d , cjcount=%d",channel,teleinfo[channel].cjcount);
			datarecord.chdevno = channel;
			pRecordData.SetEvent();
			break;
		case CHDEVZT_G:
			//发送屏显
			strcpy(dxinfo[channel].chdevztmx,chdevztmx[7]);
			//ChnPrintf(channel+1,"_STATE","写数据库成功");
			yin_fwaon(channel);
			break;
		case CHDEVZT_F:
			strcpy(dxinfo[channel].chdevztmx,chdevztmx[8]);
			//ChnPrintf(channel+1,"_STATE","未写数据库");
			yin_fwaon(channel);
			break;
		case CHDEVZT_H:
			//发送屏显
			strcpy(dxinfo[channel].chdevztmx,chdevztmx[8]);
			//ChnPrintf(channel+1,"_STATE","写数据库失败");
			yin_fwaon(channel);
			break;
		}
		break;
	case TDX_PLAYTONE:
		TRACE("--- EVENT DATA: TDX_PLAYTONE");
		// TM_TONE不处理;
		break;
	case TDX_DIAL:
		TRACE("--- EVENT DATA: TDX_DIAL");
		//这里不是通过拨号建立通话方式
		break;
	default:
		TRACE("--- EVENT TYPE AND DATA: %ld UNKNOWN",eventtype);
		//产生了其它的不须处理的事件
		break;
	}  // end switch
	return(0);
}

/*************************************************************************
* Name : end_prog()
* Input: none.
* Des:   This function stops, setonhook and closes all channels
*
**************************************************************************/
int end_prog()
{
	int i;
	unsigned long ta=0L, tm=0L;

	//关闭通道
	for(i=0;i<MAXDEVS;i++){
		if(strcmp(signlight[i].app_id,cjappid)!=0){
			continue;
		}
		dx_stopch(dxinfo[i].chdev,EV_ASYNC);
		yin_fwaon(i);
		dx_close(dxinfo[i].chdev);
		dt_close(dxinfo[i].dtdev);
		strcpy(dxinfo[i].chdevztmx,"关闭");
		clr_output(i);
	}
	//关闭语音文件
	for(i=0;i<=MAXFILES;i++){
		if(dx_fileclose(szfile[i].filehandle)==-1){
			//AfxMessageBox("close file %s error",szfile[filenumber].filename);
		    TRACE("close file error");
		}
	}
	//AfxMessageBox("All channels closed");
	return 0;
}

/*************************************************************************
*			Fuction    : int yin_mfc(int channel) 
*			Description: MultiFrequencyControl Procedure
**************************************************************************/
int yin_mfc(int channel)
{
	int fwsig;

⌨️ 快捷键说明

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