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 f_order_change DwdFOrderChange f_return DwdFReturn f_return_change DwdFReturnChange ) table1 := f_order.TableName() table2 := f_order_change.TableName() table3 := f_return.TableName() table4 := f_return_change.TableName() // 清空表 1 db, err := ClickhouseDB.DB() if err != nil { panic("获取数据库连接对象失败:" + err.Error()) } s1 := fmt.Sprintf("TRUNCATE TABLE %s.%s", GF.Clickhouse.DB, table1) _, err = db.Exec(s1) if err != nil { log.Info("清空失败", zap.String("数据表", s1)) } else { log.Info("清空成功", zap.String("数据表", s1)) } //清空表 2 s2 := fmt.Sprintf("TRUNCATE TABLE %s.%s", GF.Clickhouse.DB, table2) _, err = db.Exec(s2) if err != nil { log.Info("清空失败", zap.String("数据表", s2)) } else { log.Info("清空成功", zap.String("数据表", s2)) } //清空表 3 s3 := fmt.Sprintf("TRUNCATE TABLE %s.%s", GF.Clickhouse.DB, table3) _, err = db.Exec(s3) if err != nil { log.Info("清空失败", zap.String("数据表", s3)) } else { log.Info("清空成功", zap.String("数据表", s3)) } //清空表 4 s4 := fmt.Sprintf("TRUNCATE TABLE %s.%s", GF.Clickhouse.DB, table4) _, err = db.Exec(fmt.Sprintf("TRUNCATE TABLE %s", s4)) if err != nil { log.Info("清空失败", zap.String("数据表", s4)) } // 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" }