数据资产

收款单主表 stg_fsp_receive

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
create external table if not exists stg_fsp_receive (
id string comment '主键',
channel string comment '数据来源渠道 参照BankTradeChannelEnum 1:CB 2:ATS 3:小程序 4:手工 5:其他',
bill_type string comment '单据类型 SAAS-单据类型中获取',
bill_no string comment '单据编号',
bill_date string comment '单据日期',
bill_status string comment '单据状态 参照ReceiveBillStatusEnum 枚举值:1:已作废 、2:已红冲、3:已输入、4:已确认',
receive_company_code string comment '收款公司code 收款银行账号归属公司',
receive_sap_company_code string comment '收款公司sapcode 收款银行账号归属公司',
receive_company_name string comment '收款公司',
receive_user_name string comment '收款户名',
receive_bank string comment '收款银行',
receive_account string comment '收款银行账号',
receive_date string comment '收款日期',
payer_user_name string comment '往来方户名',
payer_account string comment '往来方银行账号',
payer_bank string comment '往来方开户行',
member_name string comment '会员姓名',
member_tel string comment '会员电话',
receive_amount string comment '',
cav_amount string comment '',
un_cav_amount string comment '未核销金额(本位币)',
currency_receive_amount string comment '',
currency string comment '换算(交易)币种',
payment_type string comment '款项类型 枚举值:1:外部收款 2:内部收款',
payment_mode string comment '支付方式 枚举值:电汇/银票/应收应付抵扣/其他',
pay_way string comment '来源 枚举值:参照 PayWayEnum 10:支付宝扫码, 11:支付宝代付, 12:支付宝APP, 20:微信扫码, 21:微信代付, 22:微信公众号, 23:微信APP, 30:银联网关, 31:银联B2B, 32:银联手机支付, 33:微信小程序支付, 34:支付宝小程序支付, 40:线下',
transaction_identifier string comment '交易唯一标识',
serial_no string comment '',
biz_company_code string comment '所属公司code 收款银行账号归属公司',
biz_sap_company_code string comment '所属公司SAPcode 收款银行账号归属公司',
biz_company_name string comment '所属公司code 收款银行账号归属公司',
payment_source string comment '款项来源 参照ReceivePaymentSourceEnum 1:主营业务收款2:非业务收款 3:处置收款 4:物流收款 5:金融收款 6:其他收款',
transaction_code string comment '交易方代码',
transaction_name string comment '交易方名称',
source_bill_type string comment '来源单据类型 ReceiveSourceTypeEnum 枚举:1:银行流水单, 2:收款拆分单, 3:小程序支付, 4:空',
source_bill_no string comment '',
before_bill_no string comment '前收款单编号 如果是原始收款单,则为空;',
old_bill_no string comment '原始收款单编号 如果是原始收款单,则同单据编号',
digest string comment '摘要',
remark string comment '备注',
confirm_user_ad string comment '确认人ad账号',
confirm_user string comment '确认人名称',
confirm_date string comment '确认日期',
void_user_ad string comment '作废人ad账号',
void_user string comment '作废人名称',
void_date string comment '作废日期',
void_message string comment '作废原因',
create_user string comment '记录创建人',
create_user_ad string comment '创建人ad账号',
create_time string comment '记录创建时间',
edit_user string comment '记录修改人',
edit_user_ad string comment '修改人ad账号',
delete_flag string comment '0表示正常1表示逻辑删除',
edit_time string comment '最后修改时间',
cav_status string comment '核销状态',
unique_key string comment '隐藏字段 支付方式、来源渠道、交易唯一标识、作废时间做为唯一索引',
old_receive_date string comment '原收款日期',
account_set_code string comment '账套编码',
account_set_version string comment '账套版本号',
local_currency string comment '本位币种',
local_currency_receive_amount string comment '本币收款金额',
exchange_rate string comment '',
channel_exchange_rate string comment '',
channel_receive_amount string comment '收款金额(收款币)',
channel_cav_amount string comment '核销金额(收款币)',
channel_un_cav_amount string comment '未核销金额(收款币)',
channel_currency string comment '收款币种',
primitive_channel_receive_amount string comment '单据初始金额',
receive_memo string comment '收款说明'
) comment '收款单' partitioned by (dt string comment '', et string comment '') STORED AS TEXTFILE LOCATION 'hdfs://prd-bd66110-zazk02.hd:8020/apps/hive/warehouse/stg.db/stg_fsp_receive' TBLPROPERTIES (
'comment' = '收款单',
'transient_lastDdlTime' = '1767862005',
'bucketing_version' = '2',
'text.compress' = 'BZIP2'
);

金税发票主表 stg_se_tax_invoice

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
create external table if not exists stg_se_tax_invoice (
id string comment '主键id',
tax_invoice_id string comment '单据标识',
bill_type string comment '单据类型',
no string comment '单据编号',
bill_date string comment '单据日期',
status string comment '状态',
corp_id string comment '公司',
creator string comment '制单人',
creator_id string comment '制单人ID',
updator string comment '修改人',
updator_id string comment '修改人ID',
auditor string comment '审批人',
auditor_id string comment '审批人ID',
audit_time string comment '审批日期',
pay_unit string comment '“”',
provide_status string comment '发放状态',
invoice_no string comment '开票编号',
total_amount string comment '总金额',
biz_unit string comment '事业部',
biz_area string comment '区域',
tax_invoice_no string comment '金税发票号码',
invoice_dept string comment '开票部门 ',
biz_shop string comment '营业店',
renting_cust string comment '签约方',
ro_nos string comment '租赁订单',
settle_nos string comment '结算单号',
invoice_type string comment '票据类型',
tax_match_no string comment '发票代码',
cus_fax_no string comment '客户税号',
cus_adr_tel string comment '客户地址电话',
cus_bank_accunt string comment '银行及帐号',
tax_invoice_date string comment '开票日期',
total_tax_amount string comment '总税额',
biz_company string comment '所属公司',
tax_rate string comment '税率',
tax_amount string comment '发票金额',
invoice_agent string comment '发票代寄',
edit_date string comment '业务修改日期',
create_time string comment '系统创建时间',
edit_time string comment '系统修改时间',
sync_time string comment '同步时间',
delete_flag string comment '0.表示正常 1.表示逻辑删除',
tax_invoice_status string comment '开票状态,10未开票、20已开票、30已作废',
model_type string comment '规格型号',
price string comment '单价',
qty string comment '数量,默认为1.00',
unit string comment '单位',
is_tax string comment '是否含税:0否/1是',
payee string comment '收款人',
reviewer string comment '复核人',
drawer string comment '开票人',
data_source string comment '数据来源:1ERP/2TP,默认为1ERP',
is_print string comment '是否打印,0否/1是,默认为1',
is_generate_express string comment '是否生成邮寄快递单,0否/1是,默认为0',
jv_merchant_code string comment '商户编号',
jv_shop_code string comment '店铺编码',
jv_pro_line string comment '业务线',
pdf_url string comment '金税pdf地址',
invoice_situation string comment '发票形势',
hand_mode string comment '交接方式',
business_type string comment '业务类型',
g3_push_status string comment '推送状态',
invoice_title string comment '发票抬头',
inside_note_type string comment '对内备注类型:0无/1发票影像/99其他备注',
inside_note string comment '对内备注',
se_invoice_no string comment '应收发票编号',
se_invoice_bill_date string comment '应收发票单据时间',
fail_message string comment '失败原因',
invoice_typeface string comment '发票类型 0 蓝字 1 红字',
relation_invoice_num string comment '关联发票号码',
relation_tax_invoice_id string comment '关联金税id',
file_url string comment '附件地址url',
upload_flag string comment '上传状态(0否 1是)',
financial_remark string comment '财务备注',
financial_remark_flag string comment '是否财务备注(0否 1是)',
file_url_ofd string comment 'ofd附件地址url',
upload_flag_ofd string comment 'ofd上传状态(0否 1是)',
file_url_xml string comment 'xml附件地址url',
upload_flag_xml string comment 'xml上传状态(0否 1是)',
issue_type string comment '开票类型 0 自动 1人工',
account_set_code string comment '账套编码',
account_set_version string comment '账套版本号',
currency_code string comment '币种code',
customer_mmp_id string comment '客户mmpid',
biz_unit_saas_code string comment '事业部code',
biz_company_saas_code string comment '公司code',
biz_shop_saas_code string comment '营业店code',
ci_invoice_date string comment 'CI开票日期',
withholding_tax_amount string comment '预扣税金额',
tax_rate_code string comment '税率编码',
terms string comment '付款期限',
relation_in_tax_no string comment '关联IN发票号码',
nn_invoice_serial_num string comment '诺诺开票流水号',
nn_invoice_message string comment '诺诺开票消息',
tax_invoice_url string comment '金税url',
invoice_definition string comment '发票定义0蓝字1红字',
create_type string comccment '创建方式',
tax_receipt_invoice_status string comment '税票状态',
qr_code_url string comment '二维码链接'
) comment '金税发票主表' partitioned by (dt string comment '日期', et string comment '服务名') ROW FORMAT DELIMITED FIELDS TERMINATED BY '\\u0001' STORED AS TEXTFILE LOCATION 'hdfs://prd-bd66110-zazk02.hd:8020/apps/hive/warehouse/stg.db/stg_se_tax_invoice' TBLPROPERTIES (
'comment' = '金税发票主表',
'transient_lastDdlTime' = '1777337854',
'bucketing_version' = '2',
'text.compress' = 'BZIP2'
);

凭证主表 ods_fac_voucher_df

业务主键:预制凭证编号
常用字段:sap凭证编号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
create external table if not exists ods_fac_voucher_df (
id string comment '明细ID',
bill_id string comment '单据流唯一id',
voucher_id string comment '凭证主表唯一编号',
prevo_avs string comment '预制凭证编号',
sap_voucher_no string comment 'sap凭证编号',
sap_transfer_time string comment 'sap过账日期',
voucher_state string comment '凭证状态:0默认,0已审批,1已作废,2已冲销',
voucher_date string comment '凭证日期',
transfer_state string comment '过账状态:0默认,0未过账,1已过账,2无需过账',
bill_check_code string comment '单据流编号(原单识别码)',
bill_no string comment '业务单据编号',
application_code string comment '接入应用编号',
scene_code string comment '场景编号',
company_code string comment '所属公司code',
sap_company_code string comment 'sap所属公司code',
vou_model_code string comment '凭证模板编号',
channel string comment '来源:0默认,0会计核算,1分录平台',
bill_classify string comment '单据分类:0默认,0原单,1冲销单,2变更单',
basic_voucher_no string comment '主凭证编号',
write_off_code string comment '冲销凭证编号',
create_user_ad string comment '制单人编号',
create_user string comment '制单人名称',
create_time string comment '制单日期',
edit_user_ad string comment '修改人编号',
edit_user string comment '修改人名称',
edit_time string comment '修改日期',
void_user_ad string comment '作废人',
void_user string comment '作废人姓名',
void_time string comment '作废时间',
transfer_user_ad string comment '过账人',
transfer_user string comment '过账人姓名',
transfer_time string comment '过账时间',
cancel_user_ad string comment '取消过账人',
cancel_user string comment '取消过账人姓名',
cancel_time string comment '取消过账时间',
delete_flag string comment '逻辑删除:0默认,0:未删除,1:已删除',
is_auto_sap string comment '是否自动推送SAP(0否1是)',
message string comment '消息'
) comment '凭证主表' partitioned by (dt string comment '日期', et string comment '业务') STORED AS PARQUET LOCATION 'hdfs://prd-bd66110-zazk02.hd:8020/apps/hive/warehouse/ods.db/ods_fac_voucher_df' TBLPROPERTIES (
'comment' = '凭证主表',
'transient_lastDdlTime' = '1740468705',
'bucketing_version' = '2',
'parquet.compression' = 'SNAPPY'
);

存货成本变动流水 ods_cost_inv_changed_record_df

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
create external table if not exists ods_cost_inv_changed_record_df (
id string comment '主键',
uuid string comment 'UUID--分库分表主键',
prefabricate_voucher_code string comment '预制凭证编号',
sap_voucher_code string comment 'SAP凭证编号',
throw_account_status string comment '抛账状态,0:未抛账;1:已抛账;默认0',
throw_account_time string comment '抛账时间',
voucher_status string comment '凭证状态,0:未生成;1:已预制;2:已过账,默认0',
voucher_prefabricate_time string comment '凭证预制时间',
voucher_post_time string comment '凭证过账时间',
voucher_msg string comment '凭证消息',
remark string comment '备注',
source string comment '来源 1、 管理批次变动流水 2、 成本调整明细',
source_order_type_code string comment '来源单据类型',
source_order_type_name string comment '来源单据类型',
source_order_no string comment '来源单据编号',
source_id string comment '来源识别码',
bat_inventory_id string comment '库存同步流水记录ID',
bat_changed_record_id string comment '管理批次变动流水ID',
cost_inv_id string comment '库存成本同步流水记录ID,会存在多个',
usage_code string comment '应用场景编号:1-财务存货核算',
batch_code string comment '1',
inventory_flow string comment '交易方向 -1:扣减;1:增加',
business_time string comment '交易时间',
accounting_date string comment '核算日期',
cost_unit string comment '核算单位',
cost_unit_name string comment '核算单位名称',
qty string comment '异动数量',
vector_qty string comment '异动数量(方向)',
currency_code string comment '币种编号',
currency_name string comment '币种名称',
cost string comment '异动成本单价',
amount string comment '异动成本金额(方向)',
business_order_type_code string comment '业务单据类型编号',
business_order_type_name string comment '业务单据类型名称',
business_order_no string comment '业务单据编号',
business_item_no string comment '业务单据商品明细号',
business_container_no string comment '业务单据码单明细号',
origin_order_type_code string comment '原始业务单据类型编号',
origin_order_type_name string comment '原始业务单据类型名称',
origin_order_no string comment '原始业务单据编号',
origin_item_no string comment '原始业务单据商品明细号',
origin_container_no string comment '原始业务单据码单明细号',
category_type string comment '商品分类:1 设备,2 主材,3 备件,4 工具,5 辅材、6 原材料,7 油液,8 耗材,9 燃料,10 材料辅材',
last_item_category_code string comment '末级品类编码',
last_item_category_name string comment '末级品类名称',
item_code string comment '商品编号',
item_name string comment '商品名称',
business_line_code string comment '业务线编码',
business_line_name string comment '业务线名称',
company_code string comment '所属公司编码',
company_name string comment '所属公司名称',
warehouse_code string comment '仓库code',
warehouse_name string comment '仓库名称',
equ_no string comment '设备编号',
batch_no string comment 'WMS业务批次号',
finance_lot_no string comment '财务批次号',
inner_business_flag string comment '内部交易标识:0-否,1-是',
inner_business_type_code string comment '关联内部交易类型code',
inner_business_type_name string comment '关联内部交易类型名称',
inner_business_code string comment '关联内部交易单据编号',
inner_business_detail_id string comment '关联内部交易单据明细ID',
dept_code string comment '业务部编号',
dept_name string comment '业务部',
shop_code string comment '营业店编号',
shop_name string comment '营业店名称',
apply_dept_code string comment '需求部门编号',
apply_dept_name string comment '需求部门名称',
project_code string comment '项目编码',
project_name string comment '项目名称',
relation_order_type string comment '关联订单类型',
relation_order_name string comment '关联订单名称',
relation_order_code string comment '关联订单编号',
relation_order_detail_id string comment '关联订单明细id',
create_by string comment '创建人ad账号',
create_by_name string comment '创建人名称',
edit_by string comment '修改人ad账号',
edit_by_name string comment '修改人名称',
create_time string comment '创建时间',
edit_time string comment '修改时间',
delete_flag string comment '是否逻辑删除:默认0,0-未删除;1-已删除',
customer_supplier_flag string comment '客商标识',
customer_supplier_code string comment '客商编号',
customer_supplier_name string comment '客商名称',
create_timestamp string comment '创建时间戳',
edit_timestamp string comment '修改时间戳',
throw_account_timestamp string comment '抛账时间戳',
voucher_prefabricate_timestamp string comment '凭证预制时间戳',
voucher_post_timestamp string comment '凭证过账时间戳',
business_timestamp string comment '交易时间戳',
accounting_date_timestamp string comment '核算日期时间戳',
account_set_code string comment '账套编码'
) comment '存货成本变动流水' partitioned by (dt string comment '日分区', et string comment '库分区') STORED AS PARQUET LOCATION 'hdfs://prd-bd66110-zazk02.hd:8020/apps/hive/warehouse/ods.db/ods_cost_inv_changed_record_df' TBLPROPERTIES (
'comment' = '存货成本变动流水',
'transient_lastDdlTime' = '1740476472',
'bucketing_version' = '2',
'parquet.compression' = 'SNAPPY'
);

用户反馈问题处理

此张报表 海外发票与收款核销匹配表 主要对 收款核销金额 该字段问题进行排查

发票id
行id 记录每张发票的行数
商品明细id 根据发票id扩展出来的商品
商品明细行id 记录商品明细行id扩展出来的行数

第一段sql 带入商品明细id(sql中的id是商品明细id),得出该字段的取值 ds.tax_invoice_detail_id
第二段sql 根据ds.tax_invoice_detail_id 字段的取值带入 收款核销金额 字段的逻辑进行数据排查

结论:根据得出的数据现象与李瑞斌沟通,确认数据问题。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
with cte_invoice_settle_detail as (     --应收发票明细表
select
h.invoice_id
, b.id
, ROW_NUMBER() OVER (PARTITION BY h.invoice_id ORDER BY b.id) AS rn2
, h.no as se_no --应收发票编号
, b.ro_no --订单编号
, coalesce(rb.parent_no,rs.parent_no) as parent_no --原结算单编号
, b.settle_no --结算单编号
, b.settle_detail_id --结算单明细ID
, st.store_name as biz_shop_saas_code --实际营业店
--, udf.get_dict_enum_desc('stg_se_invoice','business_type',h.business_type) as business_type --业务类型
, da_charge.name as charge_type_saas_code --应收费用类型
, b.tax_rate --税率
, b.tax_amount --税额
, b.tax_free_amount --不含税金额
, b.amount --价税合计
, h.total_amount --开票金额
, b.invoice_settle_detail_id --应收发票结算明细表ID
, h.biz_shop_saas_code as store_cd
from stg.stg_se_invoice h
left join ods.ods_se_invoice_settle_detail_df b
on h.invoice_id = b.invoice_id and b.dt = '2026-07-09' and b.delete_flag = '0'
left join stg.stg_se_receivable rb
on rb.no = b.settle_no and rb.dt = '2026-07-09' and rb.delete_flag = '0'
left join stg.stg_se_finance_settle_base rs
on rs.settle_no = b.settle_no and rs.dt = '2026-07-09' and rs.delete_flag = '0'
left join dwd.dim_store st
on st.store_cd = h.biz_shop_saas_code and st.dt = '2026-07-09'
left join stg.stg_sys_expense_type_translation da_charge
on b.charge_type_saas_code = da_charge.code
and da_charge.dt = '2026-07-09'
and da_charge.delete_flag = '0'
and da_charge.lang_code = 'ZH_CN'
where h.account_set_code <> 'AS_0001' and h.dt = '2026-07-09' and h.delete_flag = '0' and b.id = '15307359'
)
--b.invoice_settle_detail_id = 1009170908
--ds.tax_invoice_detail_id = 814846667467792385
,cte_se_and_settle as ( --应收发票明细表合并核销流水
select t.*
--,ROW_NUMBER() OVER (PARTITION BY t.invoice_id,t.id ORDER BY t.rn4) AS rn5
from (
select
h.*
--,d.old_bill_no
--,d.old_receive_date
--,d.invoice_amount
--,d.invoice_amount_agg
--,d.operation_date
--,d.operation_type
,ds.tax_invoice_detail_id
--,ROW_NUMBER() OVER (PARTITION BY h.invoice_id ORDER BY h.id,rn3) AS rn4

from cte_invoice_settle_detail h
left join ods.ods_se_invoice_split_detail_df s
on s.invoice_settle_detail_id = h.invoice_settle_detail_id
and s.dt = '2026-07-09'
and s.delete_flag = '0'
left join ods.ods_se_tax_invoice_detail_df ds
on ds.invoice_split_detail_id = s.invoice_split_detail_id
and ds.dt = '2026-07-09'
and ds.delete_flag = '0'
-- left join cte_se_transaction_flow d
-- on ds.tax_invoice_detail_id = d.tax_invoice_detail_id
) t
)
select * from cte_se_and_settle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
--tax_invoice_detail_id = 814846667467792385
select * from ods.ods_se_invoice_settle_detail_df
where b.dt = '2026-07-09'

--id = '213077'
select id from stg.stg_customer_invoice_balance_flow a
where bill_detail_id = '814846667467792385' and dt = '2026-07-09'
-- invoice_amount
-- 267.90000000
-- 105.75000000
-- 6.35000000
-- -380.00000000
--fund_balance_flow_id
--428799
--428800
--428801
--433334
select invoice_amount,fund_balance_flow_id from stg.stg_customer_invoice_split_detail a
where invoice_balance_flow_id = '213077' and dt = '2026-07-09'
--distributed_id
--30392946
--30392947
--30392948
--30443928
select distributed_id from stg.stg_customer_funds_flow_detail a
where dt = '2026-07-09' and id in('428799','428800','428801','433334')
--2026-01-19 00:00:00
--2026-01-19 00:00:00
--2026-01-19 00:00:00
--2026-01-20 00:00:00
select cast(cast(a.operation_date as timestamp) as date) from stg.stg_se_transaction_flow a
where dt = '2026-07-09' and distributed_id in('30392946','30392947','30392948','30443928')