clickhouse.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. package main
  2. import (
  3. "fmt"
  4. "go.uber.org/zap"
  5. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  6. "time"
  7. )
  8. // truncateClickhouse 清空Clickhouse数据表
  9. func truncateClickhouse() {
  10. var (
  11. f_order DwdFOrder
  12. //account_order_change DwdFAccountOrderChange
  13. //account_return DwdFAccountReturn
  14. //account_return_change DwdFAccountReturnChange
  15. )
  16. table1 := f_order.TableName()
  17. //table2 := account_order_change.TableName()
  18. //table3 := account_return.TableName()
  19. //table4 := account_return_change.TableName()
  20. // 清空表 1
  21. db, err := ClickhouseDB.DB()
  22. if err != nil {
  23. panic("获取数据库连接对象失败:" + err.Error())
  24. }
  25. _, err = db.Exec(fmt.Sprintf("TRUNCATE TABLE %s.%s", GF.Clickhouse.DB, table1))
  26. if err != nil {
  27. log.Info("清空失败", zap.String("数据表", table1))
  28. } else {
  29. log.Info("清空成功", zap.String("数据表", table1))
  30. }
  31. //_, err = db.Exec(fmt.Sprintf("TRUNCATE TABLE %s", table2))
  32. //if err != nil {
  33. // log.Info("清空失败", zap.String("数据表", table2))
  34. //}
  35. //
  36. //_, err = db.Exec(fmt.Sprintf("TRUNCATE TABLE %s", table3))
  37. //if err != nil {
  38. // log.Info("清空失败", zap.String("数据表", table3))
  39. //}
  40. //
  41. //_, err = db.Exec(fmt.Sprintf("TRUNCATE TABLE %s", table4))
  42. //if err != nil {
  43. // log.Info("清空失败", zap.String("数据表", table4))
  44. //}
  45. //
  46. //log.Info("所有数据表清空完毕", zap.String("数据表是:", fmt.Sprintf("%s,%s,%s,%s", table1, table2, table3, table4)))
  47. }
  48. // DwdFOrder 订单表-Clickhouse
  49. type DwdFOrder struct {
  50. ID int `gorm:"primaryKey"` // 自增 ID
  51. OrderCode string `gorm:"column:order_code"` // 订单编号
  52. SalerName string `gorm:"column:saler_name"` // 销售人员
  53. SalerDept string `gorm:"column:saler_dept"` // 部门
  54. CompanyName string `gorm:"column:company_name"` // 公司名称
  55. UserRegtime *time.Time `gorm:"column:user_regtime"` // 用户注册时间
  56. CreateTime *time.Time `gorm:"column:create_time"` // 订单创建时间
  57. ReturnTime *time.Time `gorm:"column:return_time"` // 回款时间
  58. SaleTime *time.Time `gorm:"column:sale_time"` // 业绩统计
  59. RefundTime *time.Time `gorm:"column:refund_time"` // 退款日期
  60. OriginalPrice int `gorm:"column:original_price"` // 标准售价
  61. ContractMoney int `gorm:"column:contract_money"` // 合同金额
  62. Commission int `gorm:"column:commission"` // 佣金
  63. ProceduresMoney int `gorm:"column:procedures_money"` // 手续费
  64. ReceivableAmount int `gorm:"column:receivable_amount"` // 应收金额
  65. TotalReceived int `gorm:"column:total_received"` // 累计已收
  66. ProductType string `gorm:"column:product_type"` // 产品类型
  67. DataSpec string `gorm:"column:data_spec"` // 规格
  68. OrderStatus string `gorm:"column:order_status"` // 订单状态
  69. ReturnStatus string `gorm:"column:return_status"` // 回款状态
  70. RefundStatus string `gorm:"column:refund_status"` // 退款状态
  71. VipType string `gorm:"column:vip_type"` // 付费类型
  72. UserPhone string `gorm:"column:user_phone"` // 手机号
  73. UserID string `gorm:"column:user_id"` // 用户 ID
  74. VipStarttime *time.Time `gorm:"column:vip_starttime"` // 服务开始时间
  75. VipEndtime *time.Time `gorm:"column:vip_endtime"` // 服务结束时间
  76. ContractStatus string `gorm:"column:contract_status"` // 合同状态
  77. ContractCode string `gorm:"column:contract_code"` // 合同编号
  78. ContractTime *time.Time `gorm:"column:contract_time"` // 合同时间
  79. SigningSubject string `gorm:"column:signing_subject"` // 签约主体
  80. OrderChannel string `gorm:"column:order_channel"` // 下单渠道
  81. DistributionChannel string `gorm:"column:distribution_channel"` // 销售渠道
  82. IsBackstageOrder string `gorm:"column:is_backstage_order"` // 是否是后台订单
  83. PayWay string `gorm:"column:pay_way"` // 付款方式
  84. Comeintime *time.Time `gorm:"column:comeintime;autoCreateTime"` // 入库时间
  85. Updatetime *time.Time `gorm:"column:updatetime;autoUpdateTime"` // 更新时间
  86. }
  87. func (DwdFOrder) TableName() string {
  88. return "dwd_f_order"
  89. }
  90. // DwdFOrderChange 归集后的-剑鱼业绩变更表结构体;
  91. type DwdFOrderChange struct {
  92. ID int `gorm:"primaryKey"`
  93. OrderCode string `gorm:"column:order_code;not null;comment:'订单编号'"`
  94. SalerName string `gorm:"column:saler_name;comment:'销售人员'"`
  95. SalerDept string `gorm:"column:saler_dept;comment:'部门'"`
  96. CompanyName string `gorm:"column:company_name;comment:'公司名称'"`
  97. UserRegtime *time.Time `gorm:"column:user_regtime;comment:'用户注册时间'"`
  98. CreateTime *time.Time `gorm:"column:create_time;comment:'订单创建时间'"`
  99. SaleTime *time.Time `gorm:"column:sale_time;comment:'业绩统计时间'"`
  100. OriginalPrice int `gorm:"column:original_price;comment:'标准售价'"`
  101. ContractMoney int `gorm:"column:contract_money;comment:'合同金额'"`
  102. Commission int `gorm:"column:commission;comment:'佣金'"`
  103. ProceduresMoney int `gorm:"column:procedures_money;comment:'手续费'"`
  104. ReceivableAmount int `gorm:"column:receivable_amount;comment:'应收金额'"`
  105. ChangeValue int `gorm:"column:change_value;comment:'业绩变动额'"`
  106. ChangeReason string `gorm:"column:change_reason;comment:'变更类型'"`
  107. TotalReceived int `gorm:"column:total_received;comment:'累计已收'"`
  108. ProductType string `gorm:"column:product_type;comment:'产品类型'"`
  109. DataSpec string `gorm:"column:data_spec;comment:'规格'"`
  110. OrderStatus string `gorm:"column:order_status;comment:'订单状态'"`
  111. ReturnStatus string `gorm:"column:return_status;comment:'回款状态'"`
  112. RefundStatus string `gorm:"column:refund_status;comment:'退款状态'"`
  113. VipType string `gorm:"column:vip_type;comment:'付费类型'"`
  114. UserPhone string `gorm:"column:user_phone;comment:'手机号'"`
  115. UserID string `gorm:"column:user_id;comment:'用户ID'"`
  116. VipStarttime *time.Time `gorm:"column:vip_starttime;comment:'服务开始时间'"`
  117. VipEndtime *time.Time `gorm:"column:vip_endtime;comment:'服务结束时间'"`
  118. ContractStatus string `gorm:"column:contract_status;comment:'合同状态'"`
  119. ContractCode string `gorm:"column:contract_code;comment:'合同编号'"`
  120. ContractTime *time.Time `gorm:"column:contract_time;comment:'合同时间'"`
  121. SigningSubject string `gorm:"column:signing_subject;comment:'签约主体'"`
  122. OrderChannel string `gorm:"column:order_channel;comment:'下单渠道'"`
  123. DistributionChannel string `gorm:"column:distribution_channel;comment:'销售渠道'"`
  124. IsBackstageOrder string `gorm:"column:is_backstage_order;comment:'是否是后台订单'"`
  125. PayWay string `gorm:"column:pay_way;comment:'付款方式'"`
  126. Comeintime *time.Time `gorm:"column:comeintime;default:CURRENT_TIMESTAMP;comment:'数据进入时间'"`
  127. Updatetime *time.Time `gorm:"column:updatetime;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;comment:'更新时间'"`
  128. OrderSaleRecordID int `gorm:"column:order_sale_record_id;comment:'业绩变更表ID'"`
  129. RefundRecordID int `gorm:"column:refund_record_id;comment:'退款表ID'"`
  130. }
  131. func (DwdFOrderChange) TableName() string {
  132. return "dwd_f_performance_change"
  133. }
  134. // DwdFReturn 回款表
  135. type DwdFReturn struct {
  136. ID int `gorm:"primaryKey"`
  137. OrderCode string `gorm:"column:order_code;comment:'订单编号'"`
  138. SalerName string `gorm:"column:saler_name;comment:'销售人员'"`
  139. SalerDept string `gorm:"column:saler_dept;comment:'部门'"`
  140. UserPhone string `gorm:"column:user_phone;comment:'用户手机号'"`
  141. CompanyName string `gorm:"column:company_name;comment:'公司名称'"`
  142. ProductType string `gorm:"column:product_type;comment:'产品类型'"`
  143. DataSpec string `gorm:"column:data_spec;comment:'规格'"`
  144. ReturnType string `gorm:"column:return_type;comment:'回款方式'"`
  145. SaleTime *time.Time `gorm:"column:sale_time;comment:'业绩统计日期'"`
  146. ReturnTime *time.Time `gorm:"column:return_time;comment:'回款日期'"`
  147. ReturnMoney int `gorm:"column:return_money;comment:'回款金额'"`
  148. SigningSubject string `gorm:"column:signing_subject;comment:'签约主体'"`
  149. ReturnSubject string `gorm:"column:return_subject;comment:'回款主体'"`
  150. SubjectCheck string `gorm:"column:subject_check;comment:'主体校验'"`
  151. PaymentNumber string `gorm:"column:payment_number;comment:'支付单号'"`
  152. BankFlow string `gorm:"column:bank_flow;comment:'银行流水号'"`
  153. BankName string `gorm:"column:bank_name;comment:'银行名称'"`
  154. OrderChannel string `gorm:"column:order_channel;comment:'下单渠道'"`
  155. DistributionChannel string `gorm:"column:distribution_channel;comment:'销售渠道'"`
  156. RefundStatus string `gorm:"column:refund_status;comment:'退款状态'"`
  157. OperateType string `gorm:"column:operate_type;comment:'关联方式'"`
  158. OperatePerson string `gorm:"column:operate_person;comment:'创建人'"`
  159. ReturnMoneyRecordState int `gorm:"column:return_money_record_state;comment:'数据状态'"`
  160. Comeintime *time.Time `gorm:"column:comeintime;default:CURRENT_TIMESTAMP;comment:'入库时间'"`
  161. Updatetime *time.Time `gorm:"column:updatetime;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;comment:'更新时间'"`
  162. ReturnMoneyRecordID int `gorm:"column:return_money_record_id;comment:'回款表 id'"`
  163. DataexportOrderID int `gorm:"column:dataexport_order_id;comment:'订单表 id'"`
  164. }
  165. func (DwdFReturn) TableName() string {
  166. return "dwd_f_return"
  167. }
  168. // DwdFReturnChange 回款变更表
  169. type DwdFReturnChange struct {
  170. ID int `gorm:"primaryKey;autoIncrement;comment:'自增唯一标识'"`
  171. OrderCode string `gorm:"column:order_code;comment:'订单编号'"`
  172. SalerName string `gorm:"column:saler_name;comment:'销售人员'"`
  173. SalerDept string `gorm:"column:saler_dept;comment:'部门'"`
  174. UserPhone string `gorm:"column:user_phone;comment:'用户手机号'"`
  175. CompanyName string `gorm:"column:company_name;comment:'公司名称'"`
  176. ProductType string `gorm:"column:product_type;comment:'产品类型'"`
  177. DataSpec string `gorm:"column:data_spec;comment:'规格'"`
  178. ReturnType string `gorm:"column:return_type;comment:'回款方式'"`
  179. SaleTime *time.Time `gorm:"column:sale_time;comment:'业绩变更日期'"`
  180. ReturnTime *time.Time `gorm:"column:return_time;comment:'回款日期'"`
  181. ReturnMoney int `gorm:"column:return_money;comment:'回款金额'"`
  182. ChangeValue int `gorm:"column:change_value;comment:'业绩变动额'"`
  183. ChangeReason string `gorm:"column:change_reason;comment:'变更类型'"`
  184. SigningSubject string `gorm:"column:signing_subject;comment:'签约主体'"`
  185. ReturnSubject string `gorm:"column:return_subject;comment:'回款主体'"`
  186. SubjectCheck string `gorm:"column:subject_check;comment:'主体校验'"`
  187. PaymentNumber string `gorm:"column:payment_number;comment:'支付单号'"`
  188. BankFlow string `gorm:"column:bank_flow;comment:'银行流水号'"`
  189. BankName string `gorm:"column:bank_name;comment:'银行名称'"`
  190. OrderChannel string `gorm:"column:order_channel;comment:'下单渠道'"`
  191. DistributionChannel string `gorm:"column:distribution_channel;comment:'销售渠道'"`
  192. RefundStatus string `gorm:"column:refund_status;comment:'退款状态'"`
  193. OperateType string `gorm:"column:operate_type;comment:'关联方式'"`
  194. OperatePerson string `gorm:"column:operate_person;comment:'创建人'"`
  195. OrderSaleRecordID int `gorm:"column:order_sale_record_id;comment:'业绩变更表 ID'"`
  196. RefundRecordID int `gorm:"column:refund_record_id;comment:'退款表 ID'"`
  197. Comeintime *time.Time `gorm:"column:comeintime;default:CURRENT_TIMESTAMP;comment:'入库时间'"`
  198. Updatetime *time.Time `gorm:"column:updatetime;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;comment:'更新时间'"`
  199. }
  200. func (DwdFReturnChange) TableName() string {
  201. return "dwd_f_return_change"
  202. }