----B insert overwrite table dp.pay_check_success select tb1.batch_no as batch_no, tb1.merchant_no as merchant_no, tb1.sub_merchant_no as sub_merchant_no, tb1.biz_id as biz_id, tb1.biz_amount as biz_amount, tb1.biz_date as biz_date, tb1.biz_type as biz_type, tb1.status asstatus, tb1.remark as remark, tb1.trade_date as trade_date, tb1.channel_code as channel_code from ( select tb2.batch_no as batch_no, tb1.merchant_no as merchant_no, tb1.sub_merchant_no as sub_merchant_no, tb1.biz_order_no as biz_id, tb1.trader_amount as biz_amount, \'$DP_1_DAYS_AGO_Ymd\'as biz_date, \'0\'asstatus, \'\'as remark, \'$DP_1_DAYS_AGO_Ymd\'as trade_date, tb1.channel_code as channel_code from dp.pay_check_record tb1 innerjoin dp.pay_check_channel_record tb2 on tb1.biz_order_no = tb2.biz_order_no and tb1.trader_amount = tb2.trader_amount and tb1.channel_code = tb2.channel_code where tb1.is_check = 0 and tb2.is_check = 0 and tb1.bill_date = \'$DP_1_DAYS_AGO_Ymd\' and tb2.bill_date = \'$DP_1_DAYS_AGO_Ymd\' and tb1.is_filter = 0 ) tb1
select tb2.batch_no as batch_no, tb1.merchant_no as merchant_no, tb1.sub_merchant_no as sub_merchant_no, tb1.biz_order_no as biz_id, tb1.trader_amount as biz_amount, \'$DP_1_DAYS_AGO_Ymd\'as biz_date, \'0\'asstatus, \'\'as remark, \'$DP_1_DAYS_AGO_Ymd\'as trade_date, tb1.channel_code as channel_code from dp.pay_check_record tb1 innerjoin dp.pay_check_channel_record tb2 on tb1.biz_order_no = tb2.biz_order_no and tb1.trader_amount = tb2.trader_amount and tb1.channel_code = tb2.channel_code where tb1.is_check = 0 and tb2.is_check = 0 and tb1.bill_date = \'$DP_1_DAYS_AGO_Ymd\' and tb2.bill_date = \'$DP_1_DAYS_AGO_Ymd\' and tb1.is_filter = 0
成功数据核对任务结束,将会把刚才在 DP 中创建的 pay_check_success 同步回对账系统的 MYSQL 数据库中。
存疑数据核对
存疑数据核对任务,核对的目的是为了核对出本端与对端支付单号或金额不一致的数据。
这些数据将会当做存疑数据,这些数据将会在第二阶段存疑数据处理。
这里的核对任务也是使用了 Hive SQL ,整个 SQL 跟上面比较类似,SQL 如下所示:
CREATE TABLE IF NOT EXISTS dp.check_dp_buffer_record ( `biz_id` string comment \'订单号\', `order_type` string comment \'订单类型 0本端订单 1渠道订单\', `bill_date` int comment \'对账日期\', `biz_type` int comment \'业务类型\', `channel_code` int comment \'渠道类型\', `amount` string comment \'金额\', `merchant_no` string comment \'商户号\', `sub_merchant_no` string comment \'三方子商户号\', `trade_date` int comment \'交易日期\', `create_time` string comment \'创建时间\', `update_time` string comment \'修改时间\' );
insert overwrite table dp.check_dp_buffer_record select tb1.biz_id as biz_id, tb1.order_type as order_type, tb1.bill_date as bill_date, tb1.biz_type as biz_type, tb1.channel_code as channel_code, tb1.amount as amount, tb1.merchant_no as merchant_no, tb1.sub_merchant_no as sub_merchant_no, tb1.trade_date as trade_date, \'$DP_0_DAYS_AGO_Y_m_d_HMS\', \'$DP_0_DAYS_AGO_Y_m_d_HMS\' FROM ( select tb1.biz_order_no as biz_id, 0 as order_type, tb1.bill_date as bill_date, 10 as biz_type, tb1.channel_code as channel_code, tb1.trade_amount as amount, tb1.merchant_no as merchant_no, tb1.sub_merchant_no as sub_merchant_no, \'$DP_1_DAYS_AGO_Ymd\' as trade_date FROM ( select biz_order_no, bill_date, channel_code, trade_amount, merchant_no, sub_merchant_no from ods.pay_check_record where and bill_date = \'$DP_1_DAYS_AGO_Ymd\' and is_filter = 0 and is_check = 0 ) tb1 LEFT JOIN ( select biz_order_no, trade_amount, channel_code from ods.pay_check_channel_record where and bill_date = \'$DP_1_DAYS_AGO_Ymd\' and is_check = 0 ) tb2 ON tb1.biz_order_no = tb2.biz_order_no and tb1.trade_amount = tb2.trade_amount and tb1.channel_code = tb2.channel_code where tb2.biz_order_no IS NULL union select tb1.biz_order_no as biz_id, 1 as order_type, tb1.bill_date as bill_date, 10 as biz_type, tb1.channel_code as channel_code, tb1.trade_amount as amount, tb1.merchant_no as merchant_no, tb1.sub_merchant_no as sub_merchant_no, \'$DP_1_DAYS_AGO_Ymd\' as trade_date FROM ( select biz_order_no, bill_date, channel_code, trade_amount, merchant_no, sub_merchant_no from ods.pay_check_chnnel_bill where and bill_date = \'$DP_1_DAYS_AGO_Ymd\' and is_check = 0 ) tb1 LEFT JOIN ( select biz_order_no, channel_code, trade_amount from ods.pay_check_record where and bill_date = \'$DP_1_DAYS_AGO_Ymd\' and is_filter = 0 and is_check = 0 ) tb2 ON tb1.biz_order_no = tb2.biz_order_no and tb1.trade_amount = tb2.trade_amount and tb1.channel_code = tb2.channel_code where tb2.biz_order_no IS NULL ) tb1;
select tb1.biz_order_no as biz_id, 0as order_type, tb1.bill_date as bill_date, 10as biz_type, tb1.channel_code as channel_code, tb1.trade_amount as amount, tb1.merchant_no as merchant_no, tb1.sub_merchant_no as sub_merchant_no, \'$DP_1_DAYS_AGO_Ymd\'as trade_date FROM ( select biz_order_no, bill_date, channel_code, trade_amount, merchant_no, sub_merchant_no from ods.pay_check_record where and bill_date = \'$DP_1_DAYS_AGO_Ymd\' and is_filter = 0 and is_check = 0 ) tb1 LEFTJOIN ( select biz_order_no, trade_amount, channel_code from ods.pay_check_channel_record where and bill_date = \'$DP_1_DAYS_AGO_Ymd\' and is_check = 0 ) tb2 ON tb1.biz_order_no = tb2.biz_order_no and tb1.trade_amount = tb2.trade_amount and tb1.channel_code = tb2.channel_code where tb2.biz_order_no ISNULL
SQL 看起来比较复杂,实际逻辑可以简化为下面 SQL :
select * from innerTab t1 LEFTJOIN channelTab t2 ON t1.biz_order_no = t2.biz_order_no and t1.trade_amount = t2.trade_amount and t1.channel_code = t2.channel_code where t2.biz_order_no isnull;
这里主要利用 SQL 左连接的功能,本端数据 left join 渠道数据,如果渠道单号不存在,则认为本端数据存在,渠道数据不存在,当然也有可能是两端数据都存在,但是金额不相等。
这种情况记为本端数据存疑,orderType 为 0。
渠道端单边账收集逻辑:
select tb1.biz_order_no as biz_id, 1 as order_type, tb1.bill_date as bill_date, 10 as biz_type, tb1.channel_code as channel_code, tb1.trade_amount as amount, tb1.merchant_no as merchant_no, tb1.sub_merchant_no as sub_merchant_no, \'$DP_1_DAYS_AGO_Ymd\' as trade_date FROM ( select biz_order_no, bill_date, channel_code, trade_amount, merchant_no, sub_merchant_no from ods.pay_check_chnnel_bill where and bill_date = \'$DP_1_DAYS_AGO_Ymd\' and is_check = 0 ) tb1 LEFT JOIN ( select biz_order_no, channel_code, trade_amount from ods.pay_check_record where and bill_date = \'$DP_1_DAYS_AGO_Ymd\' and is_filter = 0 and is_check = 0 ) tb2 ON tb1.biz_order_no = tb2.biz_order_no and tb1.trade_amount = tb2.trade_amount and tb1.channel_code = tb2.channel_code where tb2.biz_order_no IS NULL
逻辑与本端单边账收集类似,渠道数据 left join 本端数据,如果本端单号不存在,则为渠道数据存在,本端数据不存在。当然也有可能是两端数据都存在,但是金额不相等。