Created
October 8, 2020 08:03
-
-
Save farwydi/4a3b709b5ed8196c7331cb41b1cd214d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "gorm.io/gorm" | |
type Billing struct { | |
Id *int64 | |
Msisdn uint64 | |
RealDatetime string | |
CreateDatetime *string | |
Status int | |
Param int | |
FaultCode int | |
ServiceId int | |
Price *float64 | |
SentCount *int64 | |
Imported *bool | |
AdditionalInfo *string | |
Context *string | |
RuleId *int64 | |
DateCreate *string | |
PushedAt *string | |
CallbackAt *string | |
} | |
type Operator interface { | |
Apply(db *gorm.DB) (tx *gorm.DB) | |
} | |
type Operation struct { | |
Operators []Operator | |
} | |
func (o Operation) Load(limit int) (m []Billing) { | |
var db *gorm.DB | |
for _, operator := range o.Operators { | |
db = operator.Apply(db) | |
} | |
_ = db. | |
Where("status = 0 AND fault_code > 0"). | |
Order("create_datetime"). | |
Limit(limit). | |
Find(&m). | |
Error | |
return m | |
} | |
type _6hour struct{} | |
func (_6hour) Apply(db *gorm.DB) (tx *gorm.DB) { | |
// ретарификация через каждые 6 часов | |
return db.Where("create_datetime < now() - interval '6 hour'") | |
} | |
type _game struct{} | |
func (_game) Apply(db *gorm.DB) (tx *gorm.DB) { | |
return db. | |
// 1 ретарификация через 40 мин | |
Or("param = 1 and create_datetime <= now() - interval '40 minutes'"). | |
// 2 ретарификация через 1 час | |
Or("param = 2 and create_datetime <= now() - interval '1 hours'"). | |
// 3 ретарификация через 3 часа | |
Or("param = 3 and create_datetime <= now() - interval '3 hours'"). | |
// 4 ретарификация через 7 часов | |
Or("param = 4 and create_datetime <= now() - interval '7 hours'"). | |
// 5 ретарификация через 3 часа | |
Or("param = 5 and create_datetime <= now() - interval '3 hours'"). | |
// 6 ретарификация через 5 часов | |
Or("param = 6 and create_datetime <= now() - interval '5 hours'") | |
} | |
func main() { | |
add := Operation{[]Operator{_6hour{}, _game{}}} | |
add.Load(100) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment