123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- package main
- import (
- "fmt"
- "go.uber.org/zap"
- "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
- "time"
- )
- // truncateClickhouse 清空Clickhouse数据表
- func truncateClickhouse() {
- var (
- f_order DwdFOrder
- //account_order_change DwdFAccountOrderChange
- //account_return DwdFAccountReturn
- //account_return_change DwdFAccountReturnChange
- )
- table1 := f_order.TableName()
- //table2 := account_order_change.TableName()
- //table3 := account_return.TableName()
- //table4 := account_return_change.TableName()
- // 清空表 1
- db, err := ClickhouseDB.DB()
- if err != nil {
- panic("获取数据库连接对象失败:" + err.Error())
- }
- _, err = db.Exec(fmt.Sprintf("TRUNCATE TABLE %s.%s", GF.Clickhouse.DB, table1))
- if err != nil {
- log.Info("清空失败", zap.String("数据表", table1))
- } else {
- log.Info("清空成功", zap.String("数据表", table1))
- }
- //_, err = db.Exec(fmt.Sprintf("TRUNCATE TABLE %s", table2))
- //if err != nil {
- // log.Info("清空失败", zap.String("数据表", table2))
- //}
- //
- //_, err = db.Exec(fmt.Sprintf("TRUNCATE TABLE %s", table3))
- //if err != nil {
- // log.Info("清空失败", zap.String("数据表", table3))
- //}
- //
- //_, err = db.Exec(fmt.Sprintf("TRUNCATE TABLE %s", table4))
- //if err != nil {
- // log.Info("清空失败", zap.String("数据表", table4))
- //}
- //
- //log.Info("所有数据表清空完毕", zap.String("数据表是:", fmt.Sprintf("%s,%s,%s,%s", table1, table2, table3, table4)))
- }
- // DwdFOrder 订单表-Clickhouse
- type DwdFOrder struct {
- ID int `gorm:"primaryKey"` // 自增 ID
- OrderCode string `gorm:"column:order_code"` // 订单编号
- SalerName string `gorm:"column:saler_name"` // 销售人员
- SalerDept string `gorm:"column:saler_dept"` // 部门
- CompanyName string `gorm:"column:company_name"` // 公司名称
- UserRegtime *time.Time `gorm:"column:user_regtime"` // 用户注册时间
- CreateTime *time.Time `gorm:"column:create_time"` // 订单创建时间
- ReturnTime *time.Time `gorm:"column:return_time"` // 回款时间
- SaleTime *time.Time `gorm:"column:sale_time"` // 业绩统计
- RefundTime *time.Time `gorm:"column:refund_time"` // 退款日期
- OriginalPrice int `gorm:"column:original_price"` // 标准售价
- ContractMoney int `gorm:"column:contract_money"` // 合同金额
- Commission int `gorm:"column:commission"` // 佣金
- ProceduresMoney int `gorm:"column:procedures_money"` // 手续费
- ReceivableAmount int `gorm:"column:receivable_amount"` // 应收金额
- TotalReceived int `gorm:"column:total_received"` // 累计已收
- ProductType string `gorm:"column:product_type"` // 产品类型
- DataSpec string `gorm:"column:data_spec"` // 规格
- OrderStatus string `gorm:"column:order_status"` // 订单状态
- ReturnStatus string `gorm:"column:return_status"` // 回款状态
- RefundStatus string `gorm:"column:refund_status"` // 退款状态
- VipType string `gorm:"column:vip_type"` // 付费类型
- UserPhone string `gorm:"column:user_phone"` // 手机号
- UserID string `gorm:"column:user_id"` // 用户 ID
- VipStarttime *time.Time `gorm:"column:vip_starttime"` // 服务开始时间
- VipEndtime *time.Time `gorm:"column:vip_endtime"` // 服务结束时间
- ContractStatus string `gorm:"column:contract_status"` // 合同状态
- ContractCode string `gorm:"column:contract_code"` // 合同编号
- ContractTime *time.Time `gorm:"column:contract_time"` // 合同时间
- SigningSubject string `gorm:"column:signing_subject"` // 签约主体
- OrderChannel string `gorm:"column:order_channel"` // 下单渠道
- DistributionChannel string `gorm:"column:distribution_channel"` // 销售渠道
- IsBackstageOrder string `gorm:"column:is_backstage_order"` // 是否是后台订单
- PayWay string `gorm:"column:pay_way"` // 付款方式
- Comeintime *time.Time `gorm:"column:comeintime;autoCreateTime"` // 入库时间
- Updatetime *time.Time `gorm:"column:updatetime;autoUpdateTime"` // 更新时间
- }
- func (DwdFOrder) TableName() string {
- return "dwd_f_order"
- }
- // DwdFOrderChange 归集后的-剑鱼业绩变更表结构体;
- type DwdFOrderChange struct {
- ID int `gorm:"primaryKey"`
- OrderCode string `gorm:"column:order_code;not null;comment:'订单编号'"`
- SalerName string `gorm:"column:saler_name;comment:'销售人员'"`
- SalerDept string `gorm:"column:saler_dept;comment:'部门'"`
- CompanyName string `gorm:"column:company_name;comment:'公司名称'"`
- UserRegtime *time.Time `gorm:"column:user_regtime;comment:'用户注册时间'"`
- CreateTime *time.Time `gorm:"column:create_time;comment:'订单创建时间'"`
- SaleTime *time.Time `gorm:"column:sale_time;comment:'业绩统计时间'"`
- OriginalPrice int `gorm:"column:original_price;comment:'标准售价'"`
- ContractMoney int `gorm:"column:contract_money;comment:'合同金额'"`
- Commission int `gorm:"column:commission;comment:'佣金'"`
- ProceduresMoney int `gorm:"column:procedures_money;comment:'手续费'"`
- ReceivableAmount int `gorm:"column:receivable_amount;comment:'应收金额'"`
- ChangeValue int `gorm:"column:change_value;comment:'业绩变动额'"`
- ChangeReason string `gorm:"column:change_reason;comment:'变更类型'"`
- TotalReceived int `gorm:"column:total_received;comment:'累计已收'"`
- ProductType string `gorm:"column:product_type;comment:'产品类型'"`
- DataSpec string `gorm:"column:data_spec;comment:'规格'"`
- OrderStatus string `gorm:"column:order_status;comment:'订单状态'"`
- ReturnStatus string `gorm:"column:return_status;comment:'回款状态'"`
- RefundStatus string `gorm:"column:refund_status;comment:'退款状态'"`
- VipType string `gorm:"column:vip_type;comment:'付费类型'"`
- UserPhone string `gorm:"column:user_phone;comment:'手机号'"`
- UserID string `gorm:"column:user_id;comment:'用户ID'"`
- VipStarttime *time.Time `gorm:"column:vip_starttime;comment:'服务开始时间'"`
- VipEndtime *time.Time `gorm:"column:vip_endtime;comment:'服务结束时间'"`
- ContractStatus string `gorm:"column:contract_status;comment:'合同状态'"`
- ContractCode string `gorm:"column:contract_code;comment:'合同编号'"`
- ContractTime *time.Time `gorm:"column:contract_time;comment:'合同时间'"`
- SigningSubject string `gorm:"column:signing_subject;comment:'签约主体'"`
- OrderChannel string `gorm:"column:order_channel;comment:'下单渠道'"`
- DistributionChannel string `gorm:"column:distribution_channel;comment:'销售渠道'"`
- IsBackstageOrder string `gorm:"column:is_backstage_order;comment:'是否是后台订单'"`
- PayWay string `gorm:"column:pay_way;comment:'付款方式'"`
- Comeintime *time.Time `gorm:"column:comeintime;default:CURRENT_TIMESTAMP;comment:'数据进入时间'"`
- Updatetime *time.Time `gorm:"column:updatetime;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;comment:'更新时间'"`
- OrderSaleRecordID int `gorm:"column:order_sale_record_id;comment:'业绩变更表ID'"`
- RefundRecordID int `gorm:"column:refund_record_id;comment:'退款表ID'"`
- }
- func (DwdFOrderChange) TableName() string {
- return "dwd_f_performance_change"
- }
- // DwdFReturn 回款表
- type DwdFReturn struct {
- ID int `gorm:"primaryKey"`
- OrderCode string `gorm:"column:order_code;comment:'订单编号'"`
- SalerName string `gorm:"column:saler_name;comment:'销售人员'"`
- SalerDept string `gorm:"column:saler_dept;comment:'部门'"`
- UserPhone string `gorm:"column:user_phone;comment:'用户手机号'"`
- CompanyName string `gorm:"column:company_name;comment:'公司名称'"`
- ProductType string `gorm:"column:product_type;comment:'产品类型'"`
- DataSpec string `gorm:"column:data_spec;comment:'规格'"`
- ReturnType string `gorm:"column:return_type;comment:'回款方式'"`
- SaleTime *time.Time `gorm:"column:sale_time;comment:'业绩统计日期'"`
- ReturnTime *time.Time `gorm:"column:return_time;comment:'回款日期'"`
- ReturnMoney int `gorm:"column:return_money;comment:'回款金额'"`
- SigningSubject string `gorm:"column:signing_subject;comment:'签约主体'"`
- ReturnSubject string `gorm:"column:return_subject;comment:'回款主体'"`
- SubjectCheck string `gorm:"column:subject_check;comment:'主体校验'"`
- PaymentNumber string `gorm:"column:payment_number;comment:'支付单号'"`
- BankFlow string `gorm:"column:bank_flow;comment:'银行流水号'"`
- BankName string `gorm:"column:bank_name;comment:'银行名称'"`
- OrderChannel string `gorm:"column:order_channel;comment:'下单渠道'"`
- DistributionChannel string `gorm:"column:distribution_channel;comment:'销售渠道'"`
- RefundStatus string `gorm:"column:refund_status;comment:'退款状态'"`
- OperateType string `gorm:"column:operate_type;comment:'关联方式'"`
- OperatePerson string `gorm:"column:operate_person;comment:'创建人'"`
- ReturnMoneyRecordState int `gorm:"column:return_money_record_state;comment:'数据状态'"`
- Comeintime *time.Time `gorm:"column:comeintime;default:CURRENT_TIMESTAMP;comment:'入库时间'"`
- Updatetime *time.Time `gorm:"column:updatetime;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;comment:'更新时间'"`
- ReturnMoneyRecordID int `gorm:"column:return_money_record_id;comment:'回款表 id'"`
- DataexportOrderID int `gorm:"column:dataexport_order_id;comment:'订单表 id'"`
- }
- func (DwdFReturn) TableName() string {
- return "dwd_f_return"
- }
- // DwdFReturnChange 回款变更表
- type DwdFReturnChange struct {
- ID int `gorm:"primaryKey;autoIncrement;comment:'自增唯一标识'"`
- OrderCode string `gorm:"column:order_code;comment:'订单编号'"`
- SalerName string `gorm:"column:saler_name;comment:'销售人员'"`
- SalerDept string `gorm:"column:saler_dept;comment:'部门'"`
- UserPhone string `gorm:"column:user_phone;comment:'用户手机号'"`
- CompanyName string `gorm:"column:company_name;comment:'公司名称'"`
- ProductType string `gorm:"column:product_type;comment:'产品类型'"`
- DataSpec string `gorm:"column:data_spec;comment:'规格'"`
- ReturnType string `gorm:"column:return_type;comment:'回款方式'"`
- SaleTime *time.Time `gorm:"column:sale_time;comment:'业绩变更日期'"`
- ReturnTime *time.Time `gorm:"column:return_time;comment:'回款日期'"`
- ReturnMoney int `gorm:"column:return_money;comment:'回款金额'"`
- ChangeValue int `gorm:"column:change_value;comment:'业绩变动额'"`
- ChangeReason string `gorm:"column:change_reason;comment:'变更类型'"`
- SigningSubject string `gorm:"column:signing_subject;comment:'签约主体'"`
- ReturnSubject string `gorm:"column:return_subject;comment:'回款主体'"`
- SubjectCheck string `gorm:"column:subject_check;comment:'主体校验'"`
- PaymentNumber string `gorm:"column:payment_number;comment:'支付单号'"`
- BankFlow string `gorm:"column:bank_flow;comment:'银行流水号'"`
- BankName string `gorm:"column:bank_name;comment:'银行名称'"`
- OrderChannel string `gorm:"column:order_channel;comment:'下单渠道'"`
- DistributionChannel string `gorm:"column:distribution_channel;comment:'销售渠道'"`
- RefundStatus string `gorm:"column:refund_status;comment:'退款状态'"`
- OperateType string `gorm:"column:operate_type;comment:'关联方式'"`
- OperatePerson string `gorm:"column:operate_person;comment:'创建人'"`
- OrderSaleRecordID int `gorm:"column:order_sale_record_id;comment:'业绩变更表 ID'"`
- RefundRecordID int `gorm:"column:refund_record_id;comment:'退款表 ID'"`
- Comeintime *time.Time `gorm:"column:comeintime;default:CURRENT_TIMESTAMP;comment:'入库时间'"`
- Updatetime *time.Time `gorm:"column:updatetime;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;comment:'更新时间'"`
- }
- func (DwdFReturnChange) TableName() string {
- return "dwd_f_return_change"
- }
|