📄 net_settle.ec
字号:
/*******************************************************
* 分行对帐处理(net_settle)
* 主机对帐处理(host_settle)
*
* 最后修改: 周国祥 2001/08/16
*******************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
#include "macro_def.h"
#include "public.h"
#include "mytools.h"
#include "msgapi.h"
#include "msgsys.h"
#include "tool.h"
#define DEBIT_MODULE_ID 79
#define ARG flag, bankid, hostid, logic_date
$include "db_struct.h"
$include sqlca;
EXEC SQL WHENEVER SQLERROR CALL error_handler;
EXEC SQL WHENEVER SQLWARNING CALL warning_handler;
EXEC SQL WHENEVER NOT FOUND CALL notfound_handler;
int net_settle()
{
WINDOW *my_win, *sub_win;
char filename[1024], logic_date[11];
char str[80], rt[4], msg[20], c;
$char bankid[12], hostid[3], bankname[31];
$S_sys_param sys;
struct _bank {
char bankid[12];
char hostid[3];
char bankname[31];
} *pbank;
int count, i, j, flag;
char tmp_buf[128];
sprintf(filename, "/tmp/.net_settle.%d", getpid());
scr_dump(filename);
disp_below("分行对帐处理");
clear_wline(stdscr, LINES-1);
h_prompt(LINES-1, 1, " < ESC 退出 > ", 0, 0);
h_prompt(LINES-1, 1, "分行对帐处理", 0, 0);
my_win = newwin(19, 80, 3, 0);
mvwprintw(my_win, 0, 0, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
wrefresh(my_win);
#ifdef Wubin20020530_del
if (no_init()) {
h_winprompt(my_win, 17, 4, "系统未启动!", 1, 0);
goto quit;
}
#endif
#ifdef zgx010919_added
#else
/* 若参数配置文件中置[SETTLE]--NET_SETTLE=1 才须网间对帐 */
readtab("sysparam.tab", "SETTLE", "NET_SETTLE", tmp_buf);
if (tmp_buf[0] != '1') {
h_winprompt(my_win, 17, 4, "已约定无需进行分行网间对帐!", 1, 0);
goto quit;
}
#endif
$select * into :sys from sys_param;
if (SQLCODE) {
daylog(ERROR, "Unable select sys_param table!");
h_winprompt(my_win, 17, 4, "数据库操作错误!", 1, 0);
goto quit;
}
del_st_space("sys_param", &sys);
sprintf(filename, "select count(*) from bank_info where bank_id != adm_bank_id and host_id != adm_host_id and bank_id != '0000' and adm_bank_id = \'%s\' and adm_host_id = \'%s\'", sys.bank_id, sys.host_id);
count = query_count(filename);
if (!count) {
h_winprompt(my_win, 17, 4, "无任何下属行, 无需分行网间对帐!", 1, 0);
goto quit;
}
dateadd(sys.logic_date, -1, logic_date);
pbank = (struct _bank *)malloc(count * sizeof(struct _bank));
if (!pbank) {
daylog(ERROR, "Unable allocate memory!");
h_winprompt(my_win, 17, 4, "内存不足!", 1, 0);
goto quit;
}
$declare net_cur cursor for
select bank_id, host_id, bank_name
from bank_info
where bank_id != adm_bank_id
and host_id != adm_host_id
and bank_id != '0000'
and adm_bank_id = :sys.bank_id
and adm_host_id = :sys.host_id
order by bank_id, host_id;
$open net_cur;
if (SQLCODE) {
daylog(ERROR, "Open net_cur error!");
h_winprompt(my_win, 17, 4, "数据库操作错误!", 1, 0);
goto end;
}
for (i = 0; i < count; i++) {
$fetch net_cur into :bankid, :hostid, :bankname;
if (SQLCODE) {
daylog(ERROR, "Fetch net_cur error!");
h_winprompt(my_win, 17, 4, "数据库操作错误!", 1, 0);
$close net_cur;
goto end;
}
DelSpace(bankid);
DelSpace(hostid);
DelSpace(bankname);
strcpy(pbank[i].bankid, bankid);
strcpy(pbank[i].hostid, hostid);
strcpy(pbank[i].bankname, bankname);
}
$close net_cur;
createsbox(16, 45, 5, 18, 1, "请选择网间对帐分行 ");
for (i = 0; i < count; i++) {
sprintf(str, "%s %s", pbank[i].bankid, pbank[i].bankname);
additem(0, str, 1);
}
clear_wline(stdscr, LINES-1);
mvwprintw(stdscr, LINES-1, 23, "切换: Space 确认: Enter 取消: ESC");
refresh();
i = dispsbox();
h_prompt(LINES-1, 1, " < ESC 退出 > ", 0, 0);
h_prompt(LINES-1, 1, "分行对帐处理", 0, 0);
refresh();
if (!i) {
sprintf(str, "%-10s%-32s%8s",
"联行行号", "联行名称", "对帐结果");
CreateList(18, 56, 4, 12, str);
sub_win = newwin(16, 80, 5, 0);
scrollok(sub_win, TRUE);
wrefresh(sub_win);
for (j = 0, i = 0; i < count; i++) {
getitemflag(0, i, &c);
if (c == 0) continue;
if (j > 15) {
scroll(sub_win);
wrefresh(sub_win);
j = 15;
}
mvwprintw(sub_win, j, 4, "与 %s %s 对帐中 ...",
pbank[i].bankid, pbank[i].bankname);
wrefresh(sub_win);
daylog(DEBUG, "与 %s %s 对帐中 ...",
pbank[i].bankid, pbank[i].bankname);
settle(sys.bank_id, sys.host_id,
pbank[i].bankid, pbank[i].hostid,
logic_date, "", "", rt);
if (!memcmp(rt, "00", 2)) strcpy(msg, "对帐成功");
else get_retmsg(rt, msg);
mvwprintw(sub_win, j++, 54, "%s", msg);
wrefresh(sub_win);
daylog(DEBUG, "%s", msg);
sprintf(str, "%-10s%-32s%8s", pbank[i].bankid,
pbank[i].bankname, msg);
AddListItem(str, 0);
}
if (!j) AddListItem("未进行对帐", 1);
freesbox();
wclear(sub_win);
wrefresh(sub_win);
delwin(sub_win);
clear_wline(stdscr, LINES-1);
h_wpromptr(stdscr, LINES-1, "上移: Home PgUp ↑ 下移: End PgDn ↓ 返回: ESC", 0, 0);
refresh();
DispList(0);
FreeList();
} else freesbox();
end:
free((void *)pbank);
quit:
delwin(my_win);
scr_restore(filename);
unlink(filename);
return(0);
}
/*
* 借记卡主机对帐
*/
int host_settle()
{
char filename[128], logic_date[11], rt[4], msg[20];
$S_sys_param sys;
WINDOW *my_win;
char tmp_buf[128];
sprintf(filename, "/tmp/.host_settle.%d", getpid());
scr_dump(filename);
disp_below("主机对帐处理");
clear_wline(stdscr, LINES-1);
h_prompt(LINES-1, 1, " < ESC 退出 > ", 0, 0);
h_prompt(LINES-1, 1, "主机对帐处理", 0, 0);
my_win = newwin(19, 80, 3, 0);
mvwprintw(my_win, 0, 0, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
wrefresh(my_win);
#ifdef Wubin20020530_del
if (no_init()) {
h_winprompt(my_win, 17, 4, "系统未启动!", 1, 0);
goto host_end;
}
#endif
#ifdef zgx010919_added
#else
/* 若参数配置文件中置[SETTLE]--HOST_SETTLE=2 才须BTS发主机对帐交易 */
readtab("sysparam.tab", "SETTLE", "HOST_SETTLE", tmp_buf);
if (tmp_buf[0] != '2') {
if (tmp_buf[0] == '1')
h_winprompt(my_win, 17, 4, "主机对帐已约定由帐务主机发起!", 1, 0);
else
h_winprompt(my_win, 17, 4, "已约定无需主机对帐!", 1, 0);
goto host_end;
}
#endif
$select * into :sys from sys_param;
if (SQLCODE) {
daylog(ERROR, "Unable select sys_param table!");
h_winprompt(my_win, 17, 4, "数据库操作错误!", 1, 0);
goto host_end;
}
del_st_space("sys_param", &sys);
dateadd(sys.logic_date, -1, logic_date);
mvwprintw(my_win, 2, 4, "与主机对帐中 ...");
wrefresh(my_win);
daylog(DEBUG, "与主机对帐中 ...");
settle(sys.bank_id, sys.host_id,
sys.bank_id, sys.host_id,
logic_date, "", "", rt);
if (!memcmp(rt, "00", 2))
strcpy(msg, "对帐成功");
else
get_retmsg(rt, msg);
mvwprintw(my_win, 2, 24, "%s", msg);
wrefresh(my_win);
daylog(DEBUG, "%s", msg);
wgetch(my_win);
host_end:
delwin(my_win);
scr_restore(filename);
unlink(filename);
return(0);
}
/*
* 分行之间对帐、或主机对帐处理。
* 两个行号一样则为主机对帐
*/
int settle(cen_bankid, cen_hostid, bankid, hostid, logic_date, date, time, ret_code)
char *cen_bankid, *cen_hostid;
$parameter char *bankid, *hostid;
char *logic_date;
char *date;
char *time;
char *ret_code;
{
PUBLIC public;
$char ip_addr[21], ip_addr2[21];
char stl_bak[150];
int flag, Req_msgid, Resp_msgid;
#ifdef Wubin20020530_del
Req_msgid = gmsg_nonb(REQ_MSG);
Resp_msgid = gmsg_nonb(RESP_MSG);
if (Req_msgid < 0 || Resp_msgid < 0) {
daylog(ERROR, "Get message queue error!");
strcpy(public.Resp_code, "96");
goto stl_quit;
}
#endif
/* 两者相等表示主机对帐 */
flag = (strcmp(cen_bankid, bankid) != 0);
memset((char *)&public, 0, sizeof(PUBLIC));
strcpy(public.Acq_bank_id, cen_bankid);
strcpy(public.Acq_host_id, cen_hostid);
strcpy(public.Snd_bank_id, cen_bankid);
strcpy(public.Snd_host_id, cen_hostid);
strcpy(public.Rcv_bank_id, bankid);
strcpy(public.Rcv_host_id, hostid);
strcpy(public.Local_sys_date, date);
strcpy(public.Local_sys_time, time);
if (flag) {
$select tran_ip_addr1, tran_ip_addr2 into :ip_addr, :ip_addr2
from bank_base
where bank_id = :bankid and host_id = :hostid;
if (SQLCODE) {
daylog(ERROR, "Select ip_addr2 error!");
strcpy(public.Resp_code, "96");
goto stl_quit;
}
*((long *)&(public.Rcv_ip_addr1[0])) = inet_addr(ip_addr);
*((long *)&(public.Rcv_ip_addr2[0])) = inet_addr(ip_addr2);
}
if (flag)
public.Tran_type = NET_SETTLE;
else
public.Tran_type = HOST_SETTLE;
strcpy(public.Msg_id, "0500");
strcpy(public.Proc_code, "920000");
public.Source_msg_type = getpid();
public.Time_out = 240;
strcpy(public.Tran_sys_time, logic_date);
update_flag(flag, bankid, hostid, logic_date, 'T');
if (get_settlement(flag, bankid, hostid, logic_date, public.Add_data)) {
strcpy(public.Resp_code, "96");
goto stl_quit;
}
strcpy(stl_bak, public.Add_data);
#ifdef Wubin20020530_del
if (message_r_login(Resp_msgid, public.Source_msg_type) < 0) {
daylog(ERROR, "Message login error!");
strcpy(public.Resp_code, "96");
goto stl_quit;
}
if (message_send(Req_msgid, (char *)&public, sizeof(PUBLIC),
(flag ? TONAS_HOSTID : getid(cen_bankid, cen_hostid)), 6, 0) < 0) {
daylog(ERROR, "Message send error!");
strcpy(public.Resp_code, "96");
goto stl_end;
}
if (message_recv(Resp_msgid, (char *)&public, sizeof(PUBLIC),
&(public.Source_msg_type), 66, 0) < 0) {
daylog(ERROR, "Message recv error!");
strcpy(public.Resp_code, "96");
}
stl_end:
message_r_logout(Resp_msgid, public.Source_msg_type);
#else
if (cms_auth_deal(&public) < 0) {
daylog(ERROR, "MsgRcv Error!");
return(0);
}
#endif
stl_quit:
if (!memcmp(public.Resp_code, "00", 2))
update_flag(flag, bankid, hostid, logic_date, 'Y');
insert_settle(&public, stl_bak, bankid, hostid, logic_date);
strcpy(ret_code, public.Resp_code);
return(0);
}
int get_settlement(flag, bankid, hostid, logic_date, settlement)
int flag;
char *bankid;
char *hostid;
char *logic_date;
char *settlement;
{
int num, t_num;
double amt, t_amt;
char str[150];
if (get_total(ARG, PURCHASE, 0, &num, &amt)) return(-1);
t_num = num;
t_amt = amt;
if (get_total(ARG, WITHDRAWAL, 0, &num, &amt)) return(-1);
t_num += num;
t_amt += amt;
if (get_total(ARG, CONFIRM, 0, &num, &amt)) return(-1);
t_num += num;
t_amt += amt;
if (flag) {
flag = 2;
if (get_total(ARG, REFUND, 0, &num, &amt)) return(-1);
t_num += num;
t_amt += amt;
if (get_total(ARG, DEPOSIT, 0, &num, &amt)) return(-1);
t_num += num;
t_amt += amt;
flag = 1;
}
t_amt *= 100;
sprintf(str, "%06d%016.0f", t_num, t_amt);
if (get_total(ARG, POS_VOID, PURCHASE, &num, &amt)) return(-1);
t_num = num;
t_amt = amt;
if (get_total(ARG, POS_VOID, WITHDRAWAL, &num, &amt)) return(-1);
t_num += num;
t_amt += amt;
if (get_total(ARG, POS_VOID, CONFIRM, &num, &amt)) return(-1);
t_num += num;
t_amt += amt;
if (flag) {
flag = 2;
if (get_total(ARG, POS_VOID, REFUND, &num, &amt)) return(-1);
t_num += num;
t_amt += amt;
if (get_total(ARG, POS_VOID, DEPOSIT, &num, &amt)) return(-1);
t_num += num;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -