-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabase.dbml
More file actions
225 lines (194 loc) · 10.4 KB
/
Copy pathdatabase.dbml
File metadata and controls
225 lines (194 loc) · 10.4 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// i2c ./XXX.ets
// todo提现手续费
// 账本、资金容器
Table ledgers{
id integer [pk]
name text [note: '账本名称']
ledger_type integer [note: '账本类型(0=债务人账本,1=现金, 2=银行卡, 3=电子钱包等, 4=游戏货币)']
initial_amount real [note: '初始金额']
total_amount real [note: '当前总金额(动态更新)']
is_hide integer [note: '是否隐藏(0=False, 1=True)']
is_active integer [note: '是否启用(0=False, 1=True)']
update_time integer [note: '最后修改时间 (Unix 时间戳)']
creation_time integer [note: '创建时间 (Unix 时间戳)']
}
// 债务人/债权人表(债务主体)、关系对象
Table debtors{
id integer [pk]
name text [note: '债务人名称']
ledger_id integer [ref:> ledgers.id]
phone text [note:"手机号"]
remark text
update_time integer [note: '最后修改时间 (Unix 时间戳)']
creation_time integer [note: '创建时间 (Unix 时间戳)']
}
// 账单
Table bills{
id integer [pk]
ledger_id integer [ref:> ledgers.id]
bill_type_id integer [ref:> bill_type.id, note:"账单类型"]
initial_amount real [note:"初始金额(正数收入,负数支出"]
total_amount real [note:"最后结算结果的金额"]
transaction_time integer [note: '交易时间(Unix时间戳)']
remark text [note: '备注(如"超市购物"、"张三还款")']
update_time integer [note: '最后修改时间 (Unix 时间戳)']
creation_time integer [note: '创建时间 (Unix 时间戳)']
}
// 账单类型
Table bill_type{
id integer [pk]
name text [note: '类型名称(如"车费"、"午餐")']
icon_name text [note: '图标名称']
parent_id integer [ref:> bill_type.id, note: '父类型ID(可选)']
is_system integer [note: '是否为系统默认类型(false=用户自定义, true=系统默认)'] // 区分系统与用户类型
is_active integer [note: '是否启用(false=已删除/停用, true=正常)']
update_time integer [note: '最后修改时间 (Unix 时间戳)']
creation_time integer [note: '创建时间 (Unix 时间戳)']
}
// 子账单
Table sub_bills{
id integer [pk]
bills_id integer [ref:> bills.id, note: '关联主账单']
total_amount real [note: '子账单金额']
remark text [note: '子项备注(如"使用优惠-50元")']
update_time integer [note: '最后修改时间 (Unix 时间戳)']
creation_time integer [note: '创建时间 (Unix 时间戳)']
}
// 债务记录表(单笔债务信息)
Table loans{
id integer [pk]
ledger_id integer [ref:> ledgers.id, note: '资金所属的自有账本(如借出资金来自现金账本 )']
debtor_id integer [ref: > debtors.id,note:"借出/借入债务单位" ]
total_amount real [note: '债务总金额']
remaining_amount real [note: '剩余未还金额(动态更新)']
due_time integer [note: '到期时间 (Unix 时间戳)']
status integer [note: '状态(0=未到期, 1=已逾期, 2=已结清)']
settlement_time integer [note: '结清时间(Unix时间戳,状态为2时生效)']
remark text [note: '备注(如"2023年10月借的旅游资金")']
update_time integer [note: '最后修改时间 (Unix 时间戳)']
creation_time integer [note: '创建时间 (Unix 时间戳)']
}
// 还款明细表(债务的每笔还款记录)
Table loan_repayments{
id integer [pk]
loan_id integer [ref: > loans.id, note:"关联债务记录"]
bill_id integer [ref: > bills.id, note:"关联账单(如还款从哪个账本支出)"] // 新增:关联到具体账单
amount real [note: '本次金额(正数=还款,负数=新增欠款)']
repayment_type integer [note: '类型(0=本金, 1=利息, 2=本息合计)'] // 新增:区分还款性质
transaction_time integer [note: '交易时间(Unix时间戳)']
remark text [note: '备注(如"2023年11月分期还款")']
update_time integer [note: '最后修改时间']
creation_time integer [note: '创建时间']
}
// 消费时自动转账
Table auto_transfer{
id integer [pk]
to_ledger_id integer [ref:> ledgers.id,note:"收款账本"]
amount_type integer [note:"扣款类型(0=固定金额, 1=百分比)"]
amount real [note:"金额/占比"]
is_active integer [note: '是否启用(0=False, 1=True)']
update_time integer [note: '最后修改时间 (Unix 时间戳)']
creation_time integer [note: '创建时间 (Unix 时间戳)']
}
// 定期自动转账
Table scheduled_transfer{
id integer [pk]
to_ledger_id integer [ref:> ledgers.id,note:"收款账本"]
amount real [note:"金额"]
period integer [note:"扣款周期 (0=每天,1=每月, 2=每周)"]
execution integer [note: "每月执行日期(仅period=1时有效,1-31);每周执行星期(仅period=2时有效,1-7)"]
next_execution_time integer [note: '下次执行时间 (Unix 时间戳)']
last_execution_time integer [note: '上次执行时间 (Unix 时间戳)']
is_active integer [note: '是否启用(0=False, 1=True)']
update_time integer [note: '最后修改时间 (Unix 时间戳)']
creation_time integer [note: '创建时间 (Unix 时间戳)']
}
// 支付顺序表(管理多账本扣款优先级)
Table payment_sequence{
id integer [pk]
task_type integer [note: "任务类型(0=消费自动转账, 1=定期自动转账)"]
source_id integer [note: "关联的具体任务ID(如auto_transfer.id或scheduled_transfer.id)",ref:> auto_transfer.id,ref:> scheduled_transfer.id]
ledger_id integer [ref:> ledgers.id]
priority integer [note: "优先级(值越小越先扣款)"]
update_time integer [note: '最后修改时间 (Unix 时间戳)']
creation_time integer [note: '创建时间 (Unix 时间戳)']
}
/************************************* 理财记录 *************************************************/
// 理财产品表(优化后 )
Table financial_products {
id integer [pk]
name text [note: '产品名称']
product_code text [note: '产品唯一标识,如基金代码 “005827”、股票代码 “600036” )']
// 货币基金-份,股票型基金-份,债券型基金-份,混合型基金-份,定期理财-份/笔,股票-股,贵金属-克/份
product_type integer [note: '0=货币基金,1=股票基金,2=债券基金,3=混合型基金,4=定期理财,5=股票,6=贵金属,7=自定义(决定后续计算逻辑和单位 )']
unit_name text [note: '购买单位(如"份"、"股"、"克",根据 product_type 自动填充,便于展示和计算 )']
ledger_id integer [ref:> ledgers.id, note: '资金存入账本,用于同步资金变动到对应账本']
// 收益计算方式(0 = 净值型:通过净值波动计算收益;1 = 固定利率型:按年化利率计算 ),区分基金股票与定期理财的收益逻辑
income_calc_type integer [note: '收益计算方式(0=净值型,1=固定利率型)']
// 净值型产品的核心指标(如基金净值 1.2345 元 / 份 )
current_net_value real [note: '当前单位净值(精确到小数点后4位 )']
// 年化收益率(% ),固定利率型产品的核心指标(如定期理财年化 3.5% )
annual_income_rate real [note: '年化收益率(%)']
risk_level integer [note: '1-5级,1=低风险']
// 控制购买、赎回功能的启用状态
is_tradable integer [note: '0=不可交易,1=可交易']
// 用于定期理财等有到期日的产品提醒
due_time integer [note: '到期时间(Unix时间戳,0表示无固定期限)']
update_time integer
creation_time integer
}
// 理财交易记录表(整合份额变动 )
Table financial_transactions {
id integer [pk]
product_id integer [ref:> financial_products.id]
// 资金流向(0 = 支出 / 1 = 收入 ),直接标识交易是花钱(如购买 )还是进钱(如赎回、分红 )
fund_flow integer [note: '资金流向(0=支出,1=收入)']
// 当日利率(% ),仅固定利率型产品交易时使用(如定期理财赎回时的当日利率 )
daily_interest_rate real [note: '当日利率(%),固定利率型产品用']
transaction_type integer [note: '0=购买,1=赎回,2=分红,3=分红再投资']
// 交易金额(元 ),记录实际发生的资金变动(如购买时支出 1000 元,赎回时收入 1500 元 )
transaction_amount real [note: '交易金额(元 )']
// 变动份额(正数 = 增加,负数 = 减少 ),记录产品数量变化(如购买 100 份、赎回 50 股 )
share_amount real [note: '变动份额(正数=增加,负数=减少 )']
// 交易时单位净值(元 ),记录交易发生时的单价(如购买基金时的净值 1.2 元 / 份 )
unit_price real [note: '交易时单位净值']
// 交易费用(元 ),记录交易产生的手续费(如申购费、赎回费 )
fee_amount real [note: '交易费用(元 )']
transaction_time integer
remark text
update_time integer
creation_time integer
}
// 每日收益记录
Table financial_daily_earnings {
id integer [pk]
product_id integer [ref:> financial_products.id]
income_date integer [note: '收益日期(yyyyMMdd)'] // todo 会不会用时间戳比较好
// 当日单位净值,净值型产品当日的单价(如基金当日净值 1.2456 元 / 份 ),用于计算收益
unit_net_value real [note: '当日单位净值(净值型产品用 )']
// 前一日单位净值,净值型产品前一日的单价,与当日净值对比计算当日收益
prev_unit_net_value real [note: '前一日单位净值(净值型产品用 )']
// 当日收益金额(元 ),记录该产品当天的收益(正数 = 盈利,负数 = 亏损 )
daily_income real [note: '当日收益金额(元 )']
income_source integer [note: '0=手动录入,1=爬虫获取,2=爬虫获取但编辑过']
// 是否结算到账本(0 = 未结算 / 1 = 已结算 ),标识收益是否已同步到关联账本余额
is_settled integer [note: '0=未结算到账本,1=已结算']
// 结算时生成的账单 ID,关联到账单表,记录收益结算对应的资金流水
bill_id integer [ref:> bills.id, note: '结算时生成的账单ID']
update_time integer
creation_time integer
}
// 爬虫任务配置表
Table crawl_tasks{
id integer [pk]
product_id integer [ref:> financial_products.id, note: '关联需要爬取的理财产品']
crawl_url text [note: '爬取目标URL(如基金官网详情页 )']
crawl_time integer [note: '每日爬取时间(小时,如15表示下午3点 )']
last_crawl_time integer [note: '上次爬取时间(Unix时间戳)']
last_crawl_status integer [note: '上次爬取状态(0=未爬取,1=成功,2=失败)']
fail_reason text [note: '爬取失败原因(如"页面结构变更" )']
is_active integer [note: '是否启用爬虫(0=停用,1=启用)']
update_time integer [note: '最后修改时间 (Unix 时间戳)']
creation_time integer [note: '创建时间 (Unix 时间戳)']
}
//