batch2_model.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package fixture
  2. import (
  3. "database/sql"
  4. "time"
  5. )
  6. // 本文件是**资金域第二批 4 张表**的数据形状(外加解析 t_expenditure_log.expenditure_id
  7. // 所需的字典表 t_expenditure)。
  8. //
  9. // 与上一批的关键差别:这批第一次落地 **biz_no 口径**(旧 UUID 主键 → target int64 自增
  10. // + `biz_no varchar(32) UNIQUE` 保留旧 UUID)。对齐键因此分三类:
  11. //
  12. // 表 legacy 主键 口径 对齐键
  13. // t_user_divide_into userid int(自然键) 业务键 user_id(ULID)
  14. // t_user_divide_into_log id int AUTO_INCREMENT D1 id 原样
  15. // t_user_balance_request id varchar(32) UUID biz_no biz_no = legacy id
  16. // t_expenditure_log id varchar(32) UUID biz_no biz_no = legacy id
  17. // t_expenditure(字典) id int AUTO_INCREMENT D1 id 原样(见下表说明)
  18. //
  19. // t_expenditure 为什么也做 D1:`t_expenditure_log.expenditureid` 指向它,而它既无旧 UUID
  20. // 也无业务唯一键(name 不唯一、树结构 parentid 自引用)。要让 expenditure_id 在双跑里可对齐,
  21. // 只有「字典 id 原样保留」这一条路。目标表当前 0 行、字典 id 是 1..45 连续,D1 安全。
  22. // ⚠ 这一条属**超出本批 4 表范围的必要补充**,已在报告中标注待拍板。
  23. // ---------- t_user_divide_into ----------
  24. // LegacyDivideInto 对应 legacy `t_user_divide_into`(PK userid int,Nested Set 树)。
  25. type LegacyDivideInto struct {
  26. UserID int64
  27. Type int32
  28. Quota sql.NullString // float(10,2)
  29. TotalIncome sql.NullString // float(10,2)
  30. TotalIncomePayed sql.NullString // float(10,2)
  31. RootUserID sql.NullInt64 // 根节点时 = 自己
  32. ParentUserID sql.NullInt64 // 根节点时 = 0
  33. LeftVal int32
  34. RightVal int32
  35. Layer int32
  36. }
  37. // TargetDivideInto 对应目标 `t_user_divide_into`(自然键 user_id)。
  38. type TargetDivideInto struct {
  39. UserID string // canonical ULID
  40. Type int8
  41. QuotaCents int64
  42. TotalIncomeCents int64
  43. TotalIncomePayedCents int64
  44. RootUserID sql.NullString // ULID;legacy 0 → NULL
  45. ParentUserID sql.NullString // ULID;legacy 0(根)→ NULL
  46. LeftVal int32
  47. RightVal int32
  48. Layer int32
  49. // legacy **无** created_at/updated_at 列;目标表这两列 NOT NULL 且**无默认值**
  50. // (DDL 文件写了 DEFAULT CURRENT_TIMESTAMP(3),实际库是 GORM AutoMigrate 建的,没有默认值
  51. // —— 见报告「结构漂移」一节)。因此落 epoch 哨兵,绝不用当前时间。
  52. CreatedAt time.Time
  53. UpdatedAt time.Time
  54. }
  55. // ---------- t_user_divide_into_log ----------
  56. // LegacyDivideIntoLog 对应 legacy `t_user_divide_into_log`(PK id int AUTO_INCREMENT → D1)。
  57. type LegacyDivideIntoLog struct {
  58. ID int64
  59. Type int32 // 列类型是 tinyint unsigned zerofill,读出即 1/2
  60. UserID int64
  61. StudentID int64
  62. OrderNo sql.NullString // orderid varchar(50)
  63. Money sql.NullString // float(10,2)
  64. CreateTime sql.NullTime
  65. Remark sql.NullString // text → LONGTEXT
  66. }
  67. // TargetDivideIntoLog 对应目标 `t_user_divide_into_log`。
  68. type TargetDivideIntoLog struct {
  69. ID int64 // D1:= legacy id
  70. Type int8
  71. UserID string
  72. StudentID string
  73. OrderNo sql.NullString
  74. MoneyCents int64
  75. CreateTime time.Time
  76. Remark sql.NullString
  77. }
  78. // ---------- t_user_balance_request ----------
  79. // LegacyBalanceRequest 对应 legacy `t_user_balance_request`(PK id varchar(32) UUID → biz_no)。
  80. type LegacyBalanceRequest struct {
  81. BizNo string // 旧 UUID 主键(32 位 hex)
  82. Type int32
  83. UserID int64
  84. SchoolID int64
  85. CampusID int64
  86. Money sql.NullString // decimal(10,3)
  87. TransferAccountsType int8
  88. TransferAccountsTime sql.NullTime
  89. OrderNo sql.NullString
  90. RequestUserID int64
  91. RequestTime sql.NullTime
  92. ResponseUserID sql.NullInt64 // 0 → NULL
  93. ResponseTime sql.NullTime
  94. ResponseMsg sql.NullString
  95. Aproved int8 // 旧列名错拼,target 修正为 approved
  96. Item sql.NullString
  97. Imgs sql.NullString
  98. Remark sql.NullString
  99. }
  100. // TargetBalanceRequest 对应目标 `t_user_balance_request`。
  101. type TargetBalanceRequest struct {
  102. ID int64 // target 自增;**与 legacy 无关**
  103. BizNo string
  104. Type int32
  105. UserID string
  106. InstitutionID int64
  107. CampusID int64
  108. ToInstitutionID sql.NullInt64 // legacy 无此列 → NULL
  109. ToCampusID sql.NullInt64 // legacy 无此列 → NULL
  110. MoneyCents int64
  111. TransferAccountsType int8
  112. TransferAccountsTime sql.NullTime
  113. OrderNo sql.NullString
  114. RequestUserID string
  115. RequestTime time.Time
  116. ResponseUserID sql.NullString
  117. ResponseTime sql.NullTime
  118. ResponseMsg sql.NullString
  119. Approved int8
  120. Item sql.NullString
  121. Imgs sql.NullString
  122. Remark sql.NullString
  123. // target 的 created_at/updated_at NOT NULL 且无默认值;由 legacy 真实时间派生:
  124. // created_at = request_time(工单产生时刻)
  125. // updated_at = response_time ?? request_time(最后处理时刻)
  126. CreatedAt time.Time
  127. UpdatedAt time.Time
  128. }
  129. // ---------- t_expenditure_log ----------
  130. // LegacyExpenditureLog 对应 legacy `t_expenditure_log`(PK id varchar(32) UUID → biz_no)。
  131. type LegacyExpenditureLog struct {
  132. BizNo string
  133. SchoolID int64
  134. CampusID int64
  135. ExpenditureID int64 // → t_expenditure.id
  136. Cost sql.NullString // float(10,3)
  137. CreateUserID sql.NullInt64 // 0 → NULL
  138. CreateTime sql.NullTime
  139. Year sql.NullInt64 // MySQL YEAR 类型
  140. Month sql.NullInt64
  141. Remark sql.NullString
  142. Imgs sql.NullString
  143. }
  144. // TargetExpenditureLog 对应目标 `t_expenditure_log`。
  145. type TargetExpenditureLog struct {
  146. ID int64
  147. BizNo string
  148. InstitutionID int64
  149. CampusID int64
  150. ExpenditureID int64
  151. CostCents int64
  152. CreateUserID sql.NullString
  153. CreateTime time.Time
  154. Year sql.NullInt64
  155. Month sql.NullInt64
  156. Remark sql.NullString
  157. Imgs sql.NullString
  158. }
  159. // ---------- t_expenditure(字典,D1) ----------
  160. // LegacyExpenditure 对应 legacy `t_expenditure`(PK id int AUTO_INCREMENT,自引用树)。
  161. type LegacyExpenditure struct {
  162. ID int64
  163. Type int32
  164. ParentID int64
  165. Name string
  166. Remark sql.NullString
  167. }
  168. // TargetExpenditure 对应目标 `t_expenditure`(D1 保留 id)。
  169. type TargetExpenditure struct {
  170. ID int64
  171. Type int32
  172. ParentID int64
  173. Name string
  174. Remark sql.NullString
  175. InstitutionID int64 // legacy 无此列 → 0(平台通用字典)
  176. }