调账

/*PB3.0系统自动生成demo源码文件*/
    
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include <string.h>
#include <signal.h>
#include <setjmp.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h> 
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <dirent.h>
#include <ctype.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
    
#include "pbconstval.h"
#include "pbstructdef.h"
#include "atmi.h"   /* TUXEDO  Header File */
#include "stdarg.h"
    
#ifdef ORACLE_DATABASE
EXEC SQL include "pbranchdb.h";
#else
#include "pbranchdb.h"
#endif
#include "pberrlog.h"
#include "pbglbvardef.h"
#include "pbbasefunc.h"
EXEC SQL INCLUDE "pbappdb.h";
EXEC SQL INCLUDE "pbdbfunc.h";
EXEC SQL INCLUDE "pbbusi/busi004.h";
#define ENTRY_ROW 100
#define ENTRY_COL 1024
    
/* Fuction  :  Data_Data_AdjustAccount_RQ
 * Action   :  AdjustAccountRequest
 * Input    :
 * Output   :
 * Author   :
 * Date     : 2015/01/22
 */ 
int 
Data_AdjustAccount_RQ()
{   
    int ret = -1;
    int rellen = 1;
    char pkg_len[4+1];
    char tran_code[6+1]; 
    char area_no[6+1];
    char chnl_no[3+1];
    char busit_type[3+1];
    char clr_date[10+1];
    char record_idx[200+1];
    char acc_flag[1+1];
    char acc_type[1+1];

    memset(pkg_len, 0x00, sizeof(pkg_len));
    memset(tran_code, 0x00, sizeof(tran_code));
    memset(area_no, 0x00, sizeof(area_no));
    memset(chnl_no, 0x00, sizeof(chnl_no));
    memset(busit_type, 0x00, sizeof(busit_type));
    memset(clr_date, 0x00, sizeof(clr_date));
    memset(record_idx, 0x00, sizeof(record_idx));
    memset(acc_flag, 0x00, sizeof(acc_flag));
    memset(acc_type, 0x00, sizeof(acc_type));

    GetPoolDataByName("admin_comm", "pkg_len",0, 0, pkg_len, &rellen);
    GetPoolDataByName("admin_comm", "tran_code",0, 0, tran_code, &rellen);
    GetPoolDataByName("admin_comm", "areano",0, 0, area_no, &rellen);
    GetPoolDataByName("admin_comm", "chnlno",0, 0, chnl_no, &rellen);
    GetPoolDataByName("admin_comm", "busitype",0, 0, busit_type, &rellen);
    GetPoolDataByName("admin_comm", "clr_date",0, 0, clr_date, &rellen);
    GetPoolDataByName("admin_comm", "record_idx",0, 0, record_idx, &rellen);
    GetPoolDataByName("admin_comm", "acc_flag",0, 0, acc_flag, &rellen);
    GetPoolDataByName("admin_comm", "acc_type",0, 0, acc_type, &rellen);

    rtrim(pkg_len);
    rtrim(tran_code);
    rtrim(area_no);
    rtrim(chnl_no);
    rtrim(busit_type);
    rtrim(clr_date);
    rtrim(record_idx);
    rtrim(acc_flag);
    rtrim(acc_type);

    WriteLog(ERR_LVL,"pkg_len[%s]",pkg_len);
    WriteLog(ERR_LVL,"tran_code[%s]",tran_code);
    WriteLog(ERR_LVL,"area_no[%s]",area_no);
    WriteLog(ERR_LVL,"chnl_no[%s]",chnl_no);
    WriteLog(ERR_LVL,"busit_type[%s]",busit_type);
    WriteLog(ERR_LVL,"clr_date[%s]",clr_date);
    WriteLog(ERR_LVL,"record_idx[%s]",record_idx);
    WriteLog(ERR_LVL,"acc_flag[%s]",acc_flag);
    WriteLog(ERR_LVL,"acc_type[%s]",acc_type);

    /**** acc_flag 1-补账 2-冲账 ******/
    if( strcmp( acc_flag , "1" ) == 0 )     /* 补账 */
    {
        ret = GetPremiumAccount(clr_date,record_idx);
        if( ret != PB_OK )
        {
            WriteLog( ERR_LVL ,"Err Call GetPremiumAccount" );
            return PB_ERR;
        }   
    }
    else        /* 冲账 */
    {
        ret = GetReverseAccount(clr_date,record_idx,acc_type);
        if( ret != PB_OK )
        {
            WriteLog( ERR_LVL ,"Err Call GetReverseAccount" );
            return PB_ERR;
        }   
        
    }
    return PB_OK;
}   
    
int
GetPremiumAccount(char *clr_date,char *record_idx)
{   
    EXEC SQL BEGIN DECLARE SECTION; 
    struct S_THIRD_ACCCHK_FILE s_third_accchk_file;
    char area_no[6+1];
    char chnl_no[3+1];
    char busi_type[3+1];
    char clrdate[10+1];
    char recordidx[200+1];
    EXEC SQL END DECLARE SECTION;
    
    long hoststat=-1;
    char rem[300+1];
    
    char entry[ENTRY_ROW][ENTRY_COL];
    int entry_count = 0;
    int i =0;
    struct S_CSTM_REVER_INFO s_cstm_rever_info[1];
    char AccNum[10+1];
    double tmp_tran_amt = 0.00;
    
    int ret = -1;
    int rellen = 0;
    char tmp_str[100+1];
    char currtype[2+1]; 
    char pbjourno[10+1];
    char hostjourno[10+1];
    char listjourno[10+1];
    char trandate[8+1];

    char filename[50+1];  
    char filepath[128+1];
    char fullfilepath[256+1];
    FILE *fp = NULL;
    char strbuf[10240+1];
        
    memset(entry, 0x00, sizeof(entry));
    memset(AccNum,0,sizeof(AccNum));
    memset(&s_cstm_rever_info,0x00,sizeof(s_cstm_rever_info));
    memset(&s_third_accchk_file,0x00,sizeof(s_third_accchk_file));
    memset(tmp_str, 0x00, sizeof(tmp_str));
    memset(currtype, 0x00, sizeof(currtype));
    memset(pbjourno, 0x00, sizeof(pbjourno));
    memset(hostjourno, 0x00, sizeof(hostjourno));
    memset(listjourno, 0x00, sizeof(listjourno));
    memset(trandate, 0x00, sizeof(trandate));
    memset(filename, 0x00, sizeof(filename));
    memset(filepath, 0x00, sizeof(filepath));
    memset(fullfilepath, 0x00, sizeof(fullfilepath));
    memset(strbuf, 0x00, sizeof(strbuf));
    memset(clrdate, 0x00, sizeof(clrdate));
    memset(recordidx, 0x00, sizeof(recordidx));
    memset(rem, 0x00, sizeof(rem));
    memset(area_no, 0x00, sizeof(area_no));
    memset(chnl_no, 0x00, sizeof(chnl_no));
    memset(busi_type, 0x00, sizeof(busi_type));

    WriteLog(ERR_LVL,"========= GetPremiumAccount begin =========");

    GetPoolDataByName("admin_comm","areano",0,0,area_no,&rellen);
    GetPoolDataByName("admin_comm","chnlno",0,0,chnl_no,&rellen);
    GetPoolDataByName("admin_comm","busitype",0,0,busi_type,&rellen);

    rtrim(area_no);
    rtrim(chnl_no);
    rtrim(busi_type);

    sprintf(clrdate,"%s",clr_date);
    sprintf(recordidx,"%s",record_idx);

    WriteLog( ERR_LVL ,"clrdate[%s]",clrdate);
    WriteLog( ERR_LVL ,"recordidx[%s]",recordidx);
    WriteLog( ERR_LVL ,"area_no[%s]",area_no);
    WriteLog( ERR_LVL ,"chnl_no[%s]",chnl_no);
    WriteLog( ERR_LVL ,"busi_type[%s]",busi_type);

    /* 根据clr_date,record_idx从第三方对账文件表中抽数 */
    EXEC SQL SELECT * INTO :s_third_accchk_file
        FROM t_third_accchk_file
        WHERE clr_date = :clrdate
        AND record_idx = :recordidx
        AND areano = :area_no
        AND chnlno = :chnl_no
        AND busitype = :busi_type;

    if( SQLCODE )
    {
        WriteLog( ERR_LVL ,"Err EXEC SQL sqlcode[%d] sqlmsg[%s]",SQLCODE,SQLMSG);
        return PB_ERR;
    }

    rtrim(s_third_accchk_file.areano);
    rtrim(s_third_accchk_file.chnlno);
    rtrim(s_third_accchk_file.busitype);
    rtrim(s_third_accchk_file.clr_date);
    rtrim(s_third_accchk_file.record_idx);
    rtrim(s_third_accchk_file.tran_attr);
    rtrim(s_third_accchk_file.tran_stat);
    rtrim(s_third_accchk_file.curr_type);
    rtrim(s_third_accchk_file.ope_time);
    rtrim(s_third_accchk_file.note1);
    rtrim(s_third_accchk_file.note2);
    rtrim(s_third_accchk_file.note3);
    rtrim(s_third_accchk_file.note4);
    rtrim(s_third_accchk_file.note5);
    rtrim(s_third_accchk_file.note6);
    rtrim(s_third_accchk_file.note7);
    rtrim(s_third_accchk_file.note8);
    rtrim(s_third_accchk_file.note9);
    rtrim(s_third_accchk_file.note10);
    rtrim(s_third_accchk_file.note11);
    rtrim(s_third_accchk_file.note12);

    WriteLog( ERR_LVL ,"s_third_accchk_file.areano[%s]",s_third_accchk_file.areano);
    WriteLog( ERR_LVL ,"s_third_accchk_file.chnlno[%s]",s_third_accchk_file.chnlno);
    WriteLog( ERR_LVL ,"s_third_accchk_file.busitype[%s]",s_third_accchk_file.busitype);
    WriteLog( ERR_LVL ,"s_third_accchk_file.clr_date[%s]",s_third_accchk_file.clr_date);
    WriteLog( ERR_LVL ,"s_third_accchk_file.record_idx[%s]",s_third_accchk_file.record_idx);
    WriteLog( ERR_LVL ,"s_third_accchk_file.tran_attr[%s]",s_third_accchk_file.tran_attr);
    WriteLog( ERR_LVL ,"s_third_accchk_file.tran_stat[%s]",s_third_accchk_file.tran_stat);
    WriteLog( ERR_LVL ,"s_third_accchk_file.curr_type[%s]",s_third_accchk_file.curr_type);
    WriteLog( ERR_LVL ,"s_third_accchk_file.ope_time[%s]",s_third_accchk_file.ope_time);
    WriteLog( ERR_LVL ,"s_third_accchk_file.note1[%s]",s_third_accchk_file.note1);
    WriteLog( ERR_LVL ,"s_third_accchk_file.note1[%s]",s_third_accchk_file.note1);
    WriteLog( ERR_LVL ,"s_third_accchk_file.note2[%s]",s_third_accchk_file.note2);
    WriteLog( ERR_LVL ,"s_third_accchk_file.note3[%s]",s_third_accchk_file.note3);
    WriteLog( ERR_LVL ,"s_third_accchk_file.note4[%s]",s_third_accchk_file.note4);
    WriteLog( ERR_LVL ,"s_third_accchk_file.note5[%s]",s_third_accchk_file.note5);
    WriteLog( ERR_LVL ,"s_third_accchk_file.note6[%s]",s_third_accchk_file.note6);
    WriteLog( ERR_LVL ,"s_third_accchk_file.note7[%s]",s_third_accchk_file.note7);
    WriteLog( ERR_LVL ,"s_third_accchk_file.note8[%s]",s_third_accchk_file.note8);
    WriteLog( ERR_LVL ,"s_third_accchk_file.note9[%s]",s_third_accchk_file.note9);
    WriteLog( ERR_LVL ,"s_third_accchk_file.note10[%s]",s_third_accchk_file.note10);
    WriteLog( ERR_LVL ,"s_third_accchk_file.note11[%s]",s_third_accchk_file.note11);
    WriteLog( ERR_LVL ,"s_third_accchk_file.note12[%s]",s_third_accchk_file.note12);
        
    /******* 取出原金额进行转换  ******/
    sscanf(s_third_accchk_file.note8,"%lf",&tmp_tran_amt);
    tmp_tran_amt = tmp_tran_amt/100;
    WriteLog(ERR_LVL,"tmp_tran_amt[%lf]",tmp_tran_amt);
    
    ret = Get_pbjourno(pbjourno,hostjourno,listjourno);
    if( ret != PB_OK )
    {
        WriteLog( ERR_LVL ,"Err Get_pbjourno" );
        return PB_ERR;
    }
    GetPoolDataByName("PBSYS", "PbDate", 0, 0, trandate, &rellen );
    trim(pbjourno);
    trim(hostjourno);
    trim(listjourno);
    trim(trandate);
    WriteLog(ERR_LVL,"pbjourno[%s]",pbjourno);
    WriteLog(ERR_LVL,"hostjourno[%s]",hostjourno);
    WriteLog(ERR_LVL,"listjourno[%s]",listjourno);

    /* HostAddHead */
    ret = Data_HostAddHead("5712");
    if(ret != 0)
    {
        WriteLog(ERR_LVL,"HostAddHead failed!");
        return PB_ERR;
    }

    /* 5712 body */
    sprintf(tmp_str,"%s||%s|%lf||||||| ",s_third_accchk_file.note3,s_third_accchk_file.curr_type,tmp_tran_amt);
    WriteLog(ERR_LVL,"5712 condition[%s]",tmp_str);
    PutPoolDataByName("FDYL","checkstr",0,0,"01100301110111011011111011100000000000000000000000000000",0);
    PutPoolDataByName("FDYL","condition",0,0,tmp_str,0);

    /* 5718 body */
    PutPoolDataByName( "FDCZ", "DataFlag", 0, 0, "2" , 0 );
    sprintf( filename, "%s-%s.txt",  "900003", pbjourno );
    sprintf( filepath, "%s/%s/%s",getenv("INST_PATH"),getenv("INST_NO_PATH"), filename );
    sprintf( fullfilepath, "%s/%s",getenv("PRINTERDIR"), filepath );
    WriteLog( ERR_LVL, "filepath[%s] ", filepath );
    WriteLog( ERR_LVL, "fullfilepath[%s] ", fullfilepath );
    PutPoolDataByName( "FDCZ", "FileName", 0, 0, filepath , 0 );
    PutPoolDataByName( "FDCZ", "CorrRecordIdx", 0, 0,s_third_accchk_file.record_idx, 0 );

    fp = fopen( fullfilepath, "w+b" );
    if( NULL == fp )
    {
        WriteLog( ERR_LVL, "Open file error![%s]",fullfilepath );
        return PB_ERR;
    }

    memcpy(s_cstm_rever_info->acc_no,s_third_accchk_file.note3,19);
    s_cstm_rever_info->tran_amt = tmp_tran_amt;
    s_cstm_rever_info->fee_amt = 0.00;
    memcpy(s_cstm_rever_info->curr_type,s_third_accchk_file.curr_type,2);

    memcpy(s_cstm_rever_info->corr_flag,"1",1);
    memcpy(s_cstm_rever_info->corr_date,s_third_accchk_file.clr_date,10);
    rtrim(s_cstm_rever_info->corrseqno);
    /* 组装上传记账分录格式 */
    ret = GetEntryArray3(s_third_accchk_file.clr_date,s_cstm_rever_info,entry,&entry_count);
    if(ret != PB_OK)
    {
        WriteLog(ERR_LVL,"Err GetEntryArray3");
       return PB_ERR;
    }
    WriteLog(ERR_LVL,"entry_count[%d]",entry_count);
    
    /* 记账分录写入文件 */
    for( i = 0;i<entry_count;i++)
    {
        fprintf( fp, "%s\n", entry[i] );
        WriteLog(ERR_LVL,"entry[%s]",entry[i]);
    }
    fclose(fp);
    
    sprintf( AccNum ,"%s" , &entry_count );
    PutPoolDataByName( "FDCZ", "AccNum", 0, 0, AccNum , 0 );
        
    /* ftp file to host */
    ret = Host_ftpData( filename );
    if( ret != 0 )
    {
        WriteLog(ERR_LVL,"Host_ftpData[%s] err", filename );
        return PB_ERR;
    }
    
    WriteLog( DEBUG_LVL0, "-----------fml dopack-------------");
    ret = Data_PackFml("810|5712|0");
    if( ret < 0 )
    {
        WriteLog( ERR_LVL, "fml dopack err! " );
        return PB_ERR;
    }
    
    WriteLog( DEBUG_LVL0, "-------------call host-------------");
    ret = Comm_AcCallFml( "810|PBSVC" );
    if( ret < 0 )
    {
        WriteLog( ERR_LVL, "call host err! " );
        return PB_ERR;
    }   
        
    WriteLog( DEBUG_LVL0, "-----------fml unpack-----------");
    ret = Data_UnpackFml("810|5712|1");
    if( ret < 0 )
    {
        WriteLog( ERR_LVL, "fml unpack err! " );
        return PB_ERR;
    }
    
    GetPoolDataByName("ABSHEAD", "_host_stat", 0, 0, (char *)&hoststat, &rellen);
    WriteLog(ERR_LVL, "hoststat[%ld]", hoststat);
    if( hoststat == 0 )
    {
        WriteLog(ERR_LVL, "5712 Transaction Success![%ld]", hoststat);
    }
    else
    {
        GetPoolDataByName("ABSHEAD","_error_code",0,0,rem,&rellen);
        WriteLog(ERR_LVL ,"rem[%s]",rem);
        PutPoolDataByName("admin_comm", "ret_code", 0, 0, "1", 0);
        PutPoolDataByName("admin_comm", "ret_msg", 0, 0, rem, 0);
        return PB_ERR;
    }

    /* HostAddHead */
    ret = Data_HostAddHead("5718");
    if(ret !=0)
    {
        WriteLog(ERR_LVL,"HostAddHead failed!");
        return PB_ERR;
    }

    WriteLog(ERR_LVL,"========= GetPremiumAccount end =========");

    return PB_OK;
}

int
GetReverseAccount(char *clr_date,char *record_idx,char *acc_type)
{
    EXEC SQL BEGIN DECLARE SECTION;
    AP_JOURNAL origjnl;
    char clrdate[10+1];
    char recordidx[200+1];
    EXEC SQL END DECLARE SECTION;

    char entry[ENTRY_ROW][ENTRY_COL];
    int entry_count = 0;
    int i =0;
    struct S_CSTM_REVER_INFO s_cstm_rever_info[1];
    char AccNum[10+1];
    double tmp_tran_amt = 0.00;

    long hoststat=-1;
    char rem[300+1];

    int ret = -1;
    int rellen = 0;
    char tmp_str[100+1];
    char currtype[2+1];
    char pbjourno[10+1];
    char hostjourno[10+1];
    char listjourno[10+1];
    char trandate[8+1];
    char pb_date[8+1];

    char filename[50+1];
    char filepath[128+1];
    char fullfilepath[256+1];
    FILE *fp = NULL;
    char strbuf[10240+1];
    char curr_type[2+1];
        
    memset(entry, 0x00, sizeof(entry)); 
    memset(AccNum,0,sizeof(AccNum));
    memset(&s_cstm_rever_info,0x00,sizeof(s_cstm_rever_info));
    memset(&origjnl,0x00,sizeof(origjnl));
    memset(tmp_str, 0x00, sizeof(tmp_str));
    memset(currtype, 0x00, sizeof(currtype));
    memset(pbjourno, 0x00, sizeof(pbjourno));
    memset(hostjourno, 0x00, sizeof(hostjourno));
    memset(listjourno, 0x00, sizeof(listjourno));
    memset(trandate, 0x00, sizeof(trandate));
    memset(pb_date, 0x00, sizeof(pb_date));
    memset(filename, 0x00, sizeof(filename));
    memset(filepath, 0x00, sizeof(filepath));
    memset(fullfilepath, 0x00, sizeof(fullfilepath)); 
    memset(strbuf, 0x00, sizeof(strbuf));
    memset(clrdate, 0x00, sizeof(clrdate));
    memset(recordidx, 0x00, sizeof(recordidx));
    memset(rem, 0x00, sizeof(rem));
    memset(curr_type, 0x00, sizeof(curr_type));

    WriteLog(ERR_LVL,"========= GetReverseAccount begin =========");
    
    sprintf(clrdate,"%s",clr_date);
    sprintf(recordidx,"%s",record_idx);
    
    WriteLog( ERR_LVL ,"clrdate[%s]",clrdate);
    WriteLog( ERR_LVL ,"recordidx[%s]",recordidx);
    
    /* 根据clr_date,record_idx从t_ap_journal表中抽数 */
    EXEC SQL SELECT * INTO :origjnl
        FROM t_ap_journal
        WHERE trmstlmdtime = :clrdate
        AND appindex = :recordidx;

    if( SQLCODE )
    {
        WriteLog( ERR_LVL ,"Err EXEC SQL sqlcode[%d] sqlmsg[%s]",SQLCODE,SQLMSG);
        return PB_ERR;
    }
    
    rtrim(origjnl.AcctDate);
    rtrim(origjnl.SysSeqNum);
    rtrim(origjnl.AppIndex);
    rtrim(origjnl.TranStat);
    rtrim(origjnl.BusiType);
    rtrim(origjnl.RltAcctDate);
    rtrim(origjnl.RltSeqNo);
    rtrim(origjnl.AcctType);
    rtrim(origjnl.AcctNo);
    rtrim(origjnl.RltAcctNo);
    rtrim(origjnl.TranDate);
    rtrim(origjnl.TranTime);
    rtrim(origjnl.Track2);
    rtrim(origjnl.Track3);
    rtrim(origjnl.Crdb);
    rtrim(origjnl.TxfFlag);
    rtrim(origjnl.AuthCode);
    rtrim(origjnl.RefCode);
    rtrim(origjnl.CurrCode);
    rtrim(origjnl.StlCurrCode);
    rtrim(origjnl.TranAtt);
    rtrim(origjnl.TlrNo);
    rtrim(origjnl.BranchCode);
    rtrim(origjnl.ReqInstCode);
    rtrim(origjnl.FwdInstCode);
    rtrim(origjnl.MerType);
    rtrim(origjnl.MerCode);
    rtrim(origjnl.MerName);
    rtrim(origjnl.MerTxfDTime);
    rtrim(origjnl.ErrCode);
    rtrim(origjnl.OutTranCode);
    rtrim(origjnl.ReqChnl);
    rtrim(origjnl.TrmCode);
    rtrim(origjnl.TrmSeqNum);
    rtrim(origjnl.TrmTranDTime);
    rtrim(origjnl.TrmStlmCode);
    rtrim(origjnl.TrmStlmDTime);
    rtrim(origjnl.HstSeqNo);
    rtrim(origjnl.HstRspCode);
    rtrim(origjnl.HstStlmDTime);
    rtrim(origjnl.HostStlmCode);
    rtrim(origjnl.InstCode);
    rtrim(origjnl.InstSeqNo);
    rtrim(origjnl.InstTranDTime);
    rtrim(origjnl.InstAcctDate);
    rtrim(origjnl.InstStlmDTime);
    rtrim(origjnl.InstRspCode);
    rtrim(origjnl.FrgnAcctNo);
    rtrim(origjnl.InstStlmCode);
    rtrim(origjnl.MsgType);
    rtrim(origjnl.ProcCode);
    rtrim(origjnl.InputMode);
    rtrim(origjnl.PosCode);
    rtrim(origjnl.SChnlNo);
    rtrim(origjnl.IntTxnCode);
    rtrim(origjnl.Reserve1);
    rtrim(origjnl.Reserve2);
    rtrim(origjnl.Reserve3);
    rtrim(origjnl.Reserve4);
    rtrim(origjnl.Reserve5);
    rtrim(origjnl.Reserve6);
    rtrim(origjnl.Reserve7);

    WriteLog( ERR_LVL ,"origjnl.AcctDate[%s]",origjnl.AcctDate);
    WriteLog( ERR_LVL ,"origjnl.SysSeqNum[%s]",origjnl.SysSeqNum);
    WriteLog( ERR_LVL ,"origjnl.AppIndex[%s]",origjnl.AppIndex);
    WriteLog( ERR_LVL ,"origjnl.TranStat[%s]",origjnl.TranStat);
    WriteLog( ERR_LVL ,"origjnl.BusiType[%s]",origjnl.BusiType);
    WriteLog( ERR_LVL ,"origjnl.RltAcctDate[%s]",origjnl.RltAcctDate);
    WriteLog( ERR_LVL ,"origjnl.RltSeqNo[%s]",origjnl.RltSeqNo);
    WriteLog( ERR_LVL ,"origjnl.AcctType[%s]",origjnl.AcctType);
    WriteLog( ERR_LVL ,"origjnl.AcctNo[%s]",origjnl.AcctNo);
    WriteLog( ERR_LVL ,"origjnl.RltAcctNo[%s]",origjnl.RltAcctNo);
    WriteLog( ERR_LVL ,"origjnl.TranDate[%s]",origjnl.TranDate);
    WriteLog( ERR_LVL ,"origjnl.TranTime[%s]",origjnl.TranTime);
    WriteLog( ERR_LVL ,"origjnl.Track2[%s]",origjnl.Track2);
    WriteLog( ERR_LVL ,"origjnl.Track3[%s]",origjnl.Track3);
    WriteLog( ERR_LVL ,"origjnl.Crdb[%s]",origjnl.Crdb);
    WriteLog( ERR_LVL ,"origjnl.TxfFlag[%s]",origjnl.TxfFlag);
    WriteLog( ERR_LVL ,"origjnl.TranAmt[%lf]",origjnl.TranAmt);
    WriteLog( ERR_LVL ,"origjnl.CustFee[%lf]",origjnl.CustFee);
    WriteLog( ERR_LVL ,"origjnl.InstFee[%lf]",origjnl.InstFee);
    WriteLog( ERR_LVL ,"origjnl.AuthCode[%s]",origjnl.AuthCode);
    WriteLog( ERR_LVL ,"origjnl.RefCode[%s]",origjnl.RefCode);
    WriteLog( ERR_LVL ,"origjnl.CurrCode[%s]",origjnl.CurrCode);
    WriteLog( ERR_LVL ,"origjnl.StlCurrCode[%s]",origjnl.StlCurrCode);
    WriteLog( ERR_LVL ,"origjnl.TranAtt[%s]",origjnl.TranAtt);
    WriteLog( ERR_LVL ,"origjnl.TlrNo[%s]",origjnl.TlrNo);
    WriteLog( ERR_LVL ,"origjnl.BranchCode[%s]",origjnl.BranchCode);
    WriteLog( ERR_LVL ,"origjnl.ReqInstCode[%s]",origjnl.ReqInstCode);
    WriteLog( ERR_LVL ,"origjnl.FwdInstCode[%s]",origjnl.FwdInstCode);
    WriteLog( ERR_LVL ,"origjnl.MerType[%s]",origjnl.MerType);
    WriteLog( ERR_LVL ,"origjnl.MerCode[%s]",origjnl.MerCode);
    WriteLog( ERR_LVL ,"origjnl.MerName[%s]",origjnl.MerName);
    WriteLog( ERR_LVL ,"origjnl.MerTxfDTime[%s]",origjnl.MerTxfDTime);
    WriteLog( ERR_LVL ,"origjnl.ErrCode[%s]",origjnl.ErrCode);
    WriteLog( ERR_LVL ,"origjnl.OutTranCode[%s]",origjnl.OutTranCode);
    WriteLog( ERR_LVL ,"origjnl.ReqChnl[%s]",origjnl.ReqChnl);
    WriteLog( ERR_LVL ,"origjnl.TrmCode[%s]",origjnl.TrmCode);
    WriteLog( ERR_LVL ,"origjnl.TrmSeqNum[%s]",origjnl.TrmSeqNum);
    WriteLog( ERR_LVL ,"origjnl.TrmTranDTime[%s]",origjnl.TrmTranDTime);
    WriteLog( ERR_LVL ,"origjnl.TrmStlmCode[%s]",origjnl.TrmStlmCode);
    WriteLog( ERR_LVL ,"origjnl.TrmStlmDTime[%s]",origjnl.TrmStlmDTime);
    WriteLog( ERR_LVL ,"origjnl.HstSeqNo[%s]",origjnl.HstSeqNo);
    WriteLog( ERR_LVL ,"origjnl.HstRspCode[%s]",origjnl.HstRspCode);
    WriteLog( ERR_LVL ,"origjnl.HstStlmDTime[%s]",origjnl.HstStlmDTime);
    WriteLog( ERR_LVL ,"origjnl.HostStlmCode[%s]",origjnl.HostStlmCode);
    WriteLog( ERR_LVL ,"origjnl.InstCode[%s]",origjnl.InstCode);
    WriteLog( ERR_LVL ,"origjnl.InstSeqNo[%s]",origjnl.InstSeqNo);
    WriteLog( ERR_LVL ,"origjnl.InstTranDTime[%s]",origjnl.InstTranDTime);
    WriteLog( ERR_LVL ,"origjnl.InstAcctDate[%s]",origjnl.InstAcctDate);
    WriteLog( ERR_LVL ,"origjnl.InstStlmDTime[%s]",origjnl.InstStlmDTime);
    WriteLog( ERR_LVL ,"origjnl.InstRspCode[%s]",origjnl.InstRspCode);
    WriteLog( ERR_LVL ,"origjnl.FrgnAcctNo[%s]",origjnl.FrgnAcctNo);
    WriteLog( ERR_LVL ,"origjnl.InstStlmCode[%s]",origjnl.InstStlmCode);
    WriteLog( ERR_LVL ,"origjnl.MsgType[%s]",origjnl.MsgType);
    WriteLog( ERR_LVL ,"origjnl.ProcCode[%s]",origjnl.ProcCode);
    WriteLog( ERR_LVL ,"origjnl.InputMode[%s]",origjnl.InputMode);
    WriteLog( ERR_LVL ,"origjnl.PosCode[%s]",origjnl.PosCode);
    WriteLog( ERR_LVL ,"origjnl.SChnlNo[%s]",origjnl.SChnlNo);
    WriteLog( ERR_LVL ,"origjnl.IntTxnCode[%s]",origjnl.IntTxnCode);
    WriteLog( ERR_LVL ,"origjnl.Reserve1[%s]",origjnl.Reserve1);
    WriteLog( ERR_LVL ,"origjnl.Reserve2[%s]",origjnl.Reserve2);
    WriteLog( ERR_LVL ,"origjnl.Reserve3[%s]",origjnl.Reserve3);
    WriteLog( ERR_LVL ,"origjnl.Reserve4[%s]",origjnl.Reserve4);
    WriteLog( ERR_LVL ,"origjnl.Reserve5[%s]",origjnl.Reserve5);
    WriteLog( ERR_LVL ,"origjnl.Reserve6[%s]",origjnl.Reserve6);
    WriteLog( ERR_LVL ,"origjnl.Reserve7[%s]",origjnl.Reserve7);

    /******* 取出原金额进行转换  ******/
    sscanf(origjnl.Reserve5,"%lf",&tmp_tran_amt);
    tmp_tran_amt = tmp_tran_amt/100;
    WriteLog(ERR_LVL,"tmp_tran_amt[%lf]",tmp_tran_amt);

    /* 处理record_idx,将其赋值为pb_date+listjourno */
    memset(recordidx, 0x00, sizeof(recordidx));

    GetPoolDataByName("PBSYS", "PbDate", 0, 0, pb_date, &rellen );
    trim(pb_date);
    WriteLog( ERR_LVL, "PbDate[%s]", pb_date );

    ret = Get_pbjourno(pbjourno,hostjourno,listjourno);
    if( ret != PB_OK )
    {
        WriteLog( ERR_LVL ,"Err Get_pbjourno" );
        return PB_ERR;
    }
    GetPoolDataByName("PBSYS", "PbDate", 0, 0, trandate, &rellen );
    trim(pbjourno);
    trim(hostjourno);
    trim(listjourno);
    trim(trandate);
    WriteLog(ERR_LVL,"pbjourno[%s]",pbjourno);
    WriteLog(ERR_LVL,"hostjourno[%s]",hostjourno);
    WriteLog(ERR_LVL,"listjourno[%s]",listjourno);

    sprintf( recordidx , "%s%s",pb_date,listjourno);
    WriteLog( ERR_LVL , "recordidx[%s]",recordidx);

    /* HostAddHead */
    ret = Data_HostAddHead("5712");
    if(ret !=0)
    {
        WriteLog(ERR_LVL,"HostAddHead failed!");
        return PB_ERR;
    }

    /* 币种转换 */
    ret = get_in_currtype(origjnl.CurrCode,curr_type);
    if( ret != PB_OK )
    {
        WriteLog( ERR_LVL ," Err get_in_currtype,origjnl.CurrCode[%s]",origjnl.CurrCode);
        return PB_ERR;
    }
    
    /* 5712 body */
    sprintf(tmp_str,"%s||%s|%lf||||%s||| ",origjnl.AcctNo,curr_type,tmp_tran_amt,origjnl.Track2);
    WriteLog(ERR_LVL,"5712 condition[%s]",tmp_str);
    PutPoolDataByName("FDYL","checkstr",0,0,"01111311110111111011111011100000000000000000000000000000",0);
    PutPoolDataByName("FDYL","condition",0,0,tmp_str,0);
    
    /* 5718 body */
    PutPoolDataByName( "FDCZ", "DataFlag", 0, 0, "2" , 0 );
    sprintf( filename, "%s-%s.txt",  "900003", pbjourno );
    sprintf( filepath, "%s/%s/%s",getenv("INST_PATH"),getenv("INST_NO_PATH"), filename );
    sprintf( fullfilepath, "%s/%s",getenv("PRINTERDIR"), filepath );
    WriteLog( ERR_LVL, "filepath[%s] ", filepath );
    WriteLog( ERR_LVL, "fullfilepath[%s] ", fullfilepath );
    PutPoolDataByName( "FDCZ", "FileName", 0, 0, filepath , 0 );
    PutPoolDataByName( "FDCZ", "CorrRecordIdx", 0, 0, origjnl.AppIndex , 0 );

    fp = fopen( fullfilepath, "w+b" );
    if( NULL == fp )
    {
        WriteLog( ERR_LVL, "Open file error![%s]",fullfilepath );
        return PB_ERR;
    }
    
    memcpy(s_cstm_rever_info->acc_no,origjnl.AcctNo,19);
    s_cstm_rever_info->tran_amt = tmp_tran_amt;
    s_cstm_rever_info->fee_amt = 0.00;
    memcpy(s_cstm_rever_info->curr_type,curr_type,2);
    
    memcpy(s_cstm_rever_info->corr_flag,"1",1);
    memcpy(s_cstm_rever_info->corr_date,origjnl.AcctDate,10);
    sprintf(s_cstm_rever_info->corrseqno,"TT%s",origjnl.SysSeqNum);
    
    /*****   根据 acc_type冲账类型 1-蓝字冲账 2-红字冲账 调用不同分录 ******/
    if( strcmp( acc_type , "1" ) == 0)  /***** 1-蓝字冲账 ****/
    {
        /* 组装上传记账分录格式 */
        ret = GetReverEntry(origjnl.AcctDate,s_cstm_rever_info,entry,&entry_count);
        if(ret != PB_OK)
        {
            WriteLog(ERR_LVL,"Err GetReverEntry");
            return PB_ERR;
        }
    }   
    else        /***** 2-红字冲账 ****/
    {
        /* 组装上传记账分录格式 */
        s_cstm_rever_info->tran_amt =  (-1)*s_cstm_rever_info->tran_amt;
        ret = GetJourEntryArray3(origjnl.AcctDate,s_cstm_rever_info,entry,&entry_count);
        if(ret != PB_OK)
        {
            WriteLog(ERR_LVL,"Err GetJourEntryArray3");
            return PB_ERR;
        }
    }

    WriteLog(ERR_LVL,"entry_count[%d]",entry_count);

    /* 记账分录写入文件 */
    for( i = 0;i<entry_count;i++)
    {
        fprintf( fp, "%s\n", entry[i] );
        WriteLog(ERR_LVL,"entry[%s]",entry[i]);
    }
    fclose(fp);

    sprintf( AccNum ,"%s" , &entry_count );
    PutPoolDataByName( "FDCZ", "AccNum", 0, 0, AccNum , 0 );

    /* ftp file to host */
    ret = Host_ftpData( filename );
    if( ret != 0 )
    {
        WriteLog(ERR_LVL,"Host_ftpData[%s] err", filename );
        return PB_ERR;
    }

    WriteLog( DEBUG_LVL0, "-----------fml dopack-------------");
    ret = Data_PackFml("810|5712|0");
    if( ret < 0 )
    {
        WriteLog( ERR_LVL, "fml dopack err! " );
        return PB_ERR;
    }

    WriteLog( DEBUG_LVL0, "-------------call host-------------");
    ret = Comm_AcCallFml( "810|PBSVC" );
    if( ret < 0 )
    {
        WriteLog( ERR_LVL, "call host err! " );
        return PB_ERR;
    }

    WriteLog( DEBUG_LVL0, "-----------fml unpack-----------");
    ret = Data_UnpackFml("810|5712|1");
    if( ret < 0 )
    {
        WriteLog( ERR_LVL, "fml unpack err! " );
        return PB_ERR;
    }

    GetPoolDataByName("ABSHEAD", "_host_stat", 0, 0, (char *)&hoststat, &rellen);
    WriteLog(ERR_LVL, "hoststat[%ld]", hoststat);
    if( hoststat == 0 )
    {
        WriteLog(ERR_LVL, "5712 Transaction Success![%ld]", hoststat);
    }
    else
    {
        GetPoolDataByName("ABSHEAD","_error_code",0,0,rem,&rellen);
        WriteLog(ERR_LVL ,"rem[%s]",rem);
        PutPoolDataByName("admin_comm", "ret_code", 0, 0, "1", 0);
        PutPoolDataByName("admin_comm", "ret_msg", 0, 0, rem, 0);
        return PB_ERR;
    }
        
    /* HostAddHead */
    ret = Data_HostAddHead("5718");
    if(ret !=0)
    {
        WriteLog(ERR_LVL,"HostAddHead failed!");
        return PB_ERR; 
    }
    
    WriteLog(ERR_LVL,"========= GetReverseAccount end =========");
    
    return PB_OK;
}       
        
int 
Data_AdjustAccount_RP()
{   
    int ret=-1;
    int rellen=0;
    long hoststat=-1;
    char ret_code[1+1];
    char ret_msg[100+1];
    char rem[300+1];
    char rem_str[32+1];
    char errcode[10+1];
    char errmsg[300+1];
    char record_idx[200+1];
    char clr_date[10+1];
    char acc_flag[1+1];
        
    memset(errcode,0x00,sizeof(errcode));
    memset(errmsg,0x00,sizeof(errmsg));
    memset(rem,0x00,sizeof(rem));
    memset(rem_str,0x00,sizeof(rem_str));
    memset(rem_str,0x00,sizeof(rem_str));
    memset(ret_code,0x00,sizeof(ret_code));
    memset(record_idx,0x00,sizeof(record_idx));
    memset(clr_date,0x00,sizeof(clr_date));
    memset(acc_flag,0x00,sizeof(acc_flag));

    GetPoolDataByName("admin_comm", "clr_date",0, 0, clr_date, &rellen);
    GetPoolDataByName("admin_comm", "record_idx",0, 0, record_idx, &rellen);
    GetPoolDataByName("admin_comm", "acc_flag",0, 0, acc_flag, &rellen);
    
    rtrim(clr_date);
    rtrim(record_idx);
    rtrim(acc_flag);

    WriteLog( ERR_LVL , "============== Data_AdjustAccount_RP[900003] begin ============");
    GetPoolDataByName("ABSHEAD", "_host_stat", 0, 0, (char *)&hoststat, &rellen);
    WriteLog(ERR_LVL, "hoststat[%ld]", hoststat);
    if( hoststat == 0 )
    {
        WriteLog(ERR_LVL, "Transaction Success![%ld]", hoststat);

        if( strcmp(acc_flag,"2") == 0 )     /* 冲账交易成功,update t_ap_journal表 */
        {
            ret = setFlagAfterReversal(record_idx, clr_date);
            if(ret == PB_OK)
            {
                WriteLog(ERR_LVL, "update table T_AP_JOURNAL successfully!");
            }
        }
        PutPoolDataByName("admin_comm", "ret_code", 0, 0, "0", 0);
        PutPoolDataByName("admin_comm", "ret_msg", 0, 0, "交易成功", 0);
        WriteLog(ERR_LVL, "Adjust accounts successfully!");
    }
    else
    {
        memset( rem , 0x00, sizeof(rem));
        GetPoolDataByName("ABSHEAD","_error_code",0,0,rem,&rellen);
        WriteLog(ERR_LVL ,"rem[%s]",rem);
        PutPoolDataByName("admin_comm", "ret_code", 0, 0, "1", 0);
        PutPoolDataByName("admin_comm", "ret_msg", 0, 0, "调用失败", 0);
        return PB_ERR;
    }

    WriteLog( ERR_LVL , "============== Data_AdjustAccount_RP[900003] end ============");
    return PB_OK;
}

/* Fuction  :  setFlagAfterReversal
 * Action   :  update table T_AP_JOURNAL after cash withdrawal Reserval successfully
 * Input    :
 * Output   :
 * Author   :
 * Date     : 2014/12/09
 */
int setFlagAfterReversal(char *record_idx, char *clr_date)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char recordidx[200+1];
    char clrdate[10+1];
    EXEC SQL END DECLARE SECTION;
    memset(recordidx, 0x00, sizeof(recordidx));
    memset(clrdate, 0x00, sizeof(clrdate));

    memcpy(recordidx, record_idx, strlen(record_idx));
    memcpy(clrdate, clr_date, 10);

    WriteLog(ERR_LVL, "recordidx=[%s], clrdate=[%s]", recordidx, clrdate);
    EXEC SQL UPDATE T_AP_JOURNAL
        SET TRANSTAT='9' 
        WHERE appindex =:recordidx 
        AND trmstlmdtime =:clrdate 
        AND transtat='0';
    if( SQLCODE || sqlca.sqlerrd[2] != 1)
    {   
        WriteLog(ERR_LVL, "update table T_AP_JOURNAL fail! SQLCODE=[%d], SQLMSG=[%s]", SQLCODE, SQLMSG );
        return PB_ERR;
    }   
    WriteLog(ERR_LVL, "successfully! SQLCODE=[%d]!SQLMSG=[%s]", SQLCODE, SQLMSG );
    return PB_OK;
}

内容概要:该论文研究了一种基于行波理论的输电线路故障诊断方法。当输电线路发生故障时,故障点会产生向两侧传播的电流和电压行波。通过相模变换对三相电流行波解耦,利用解耦后独立模量间的关系确定故障类型和相别,再采用小波变换模极大值法标定行波波头,从而计算故障点距离。仿真结果表明,该方法能准确识别故障类型和相别,并对故障点定位具有高精度。研究使用MATLAB进行仿真验证,为输电线路故障诊断提供了有效解决方案。文中详细介绍了三相电流信号生成、相模变换(Clarke变换)、小波变换波头检测、故障诊断主流程以及结果可视化等步骤,并通过多个实例验证了方法的有效性和准确性。 适合人群:具备一定电力系统基础知识和编程能力的专业人士,特别是从事电力系统保护与控制领域的工程师和技术人员。 使用场景及目标:①适用于电力系统的故障检测与诊断;②能够快速准确地识别输电线路的故障类型、相别及故障点位置;③为电力系统的安全稳定运行提供技术支持,减少停电时间和损失。 其他说明:该方法不仅在理论上进行了深入探讨,还提供了完整的Python代码实现,便于读者理解和实践。此外,文中还讨论了行波理论的核心公式、三相线路行波解耦、行波测距实现等关键技术点,并针对工程应用给出了注意事项,如波速校准、采样率要求、噪声处理等。这使得该方法不仅具有学术价值,也具有很强的实际应用前景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值