// Copyright 2019 getensh.com. All rights reserved. // Use of this source code is governed by getensh.com. // package impl implement all interfaces of micro service in gd_crontab package impl import ( "context" "gd_crontab/apis" "gd_crontab/impl/accounting" "gd_crontab/impl/crontab" "gd_crontab/impl/warning" "fmt" "github.com/robfig/cron" "gd_crontab/common.in/config" "gd_crontab/common.in/task" "github.com/astaxie/beego/orm" ) // 具体实现 type Rcvr struct { } // TODO delete func (c *Rcvr) WarningApiCount(ctx context.Context, req *apis.WarningApiCountReq, reply *apis.WarningApiCountReply) error { t1 := func() error { return warning.WarningApiCount(ctx, req, reply) } return task.Do(ctx, t1) } // TODO delete func (c *Rcvr) WarningProviderCount(ctx context.Context, req *apis.WarningProviderCountReq, reply *apis.WarningProviderCountReply) error { t1 := func() error { return warning.WarningProviderCount(ctx, req, reply) } return task.Do(ctx, t1) } func (c *Rcvr) LogGenerateReport(ctx context.Context, req *apis.LogGenerateReportReq, reply *apis.LogGenerateReportReply) error { t1 := func() error { return crontab.LogGenerateReport(ctx, req, reply) } return task.Do(ctx, t1) } func (c *Rcvr) LogQueryProviderCountExport(ctx context.Context, req *apis.LogQueryProviderCountExportReq, reply *apis.LogQueryProviderCountExportReply) error { t1 := func() error { return crontab.LogQueryProviderCountExport(ctx, req, reply) } return task.Do(ctx, t1) } func (c *Rcvr) ExportProviderDay(ctx context.Context, req *apis.LogQueryProviderCountExportReq, reply *apis.LogQueryProviderCountExportReply) error { t1 := func() error { return crontab.ExportProviderDay(ctx, req, reply) } return task.Do(ctx, t1) } func (c *Rcvr) ReciveAccessLog(ctx context.Context, req *apis.ReciveAccessLogReq, reply *apis.ReciveAccessLogReply) error { t1 := func() error { return warning.ReciveAccessLog(ctx, req, reply) } return task.Do(ctx, t1) } func (c *Rcvr) ReciveThirdPartLog(ctx context.Context, req *apis.ReciveThirdPartLogReq, reply *apis.ReciveThirdPartLogReply) error { t1 := func() error { return warning.ReciveThirdPartLog(ctx, req, reply) } return task.Do(ctx, t1) } func RegisterOrmModel() { //orm.RegisterModel(new(apis.AccessLog)) //orm.RegisterModel(new(apis.TGdAccessLogHistory)) //orm.RegisterModel(new(apis.ThirdpartLog)) //orm.RegisterModel(new(apis.TGdThirdpartAccessLogHistory)) orm.RegisterModel(new(crontab.TGdReport)) orm.RegisterModel(new(crontab.TGdBusinessReport)) orm.RegisterModel(new(crontab.TGdProviderReport)) orm.RegisterModel(new(crontab.TGdReportHour)) orm.RegisterModel(new(crontab.TGdProviderReportHour)) orm.RegisterModel(new(crontab.TGdProviderCodeHour)) orm.RegisterModel(new(crontab.TGdApiCodeHour)) orm.RegisterModel(new(apis.AccessLogDay)) orm.RegisterModel(new(apis.ThirdpartLogDay)) orm.RegisterModel(new(apis.TGdAccessLogMonth1)) orm.RegisterModel(new(apis.TGdAccessLogMonth2)) orm.RegisterModel(new(apis.TGdAccessLogMonth3)) orm.RegisterModel(new(apis.TGdAccessLogMonth4)) orm.RegisterModel(new(apis.TGdAccessLogMonth5)) orm.RegisterModel(new(apis.TGdAccessLogMonth6)) orm.RegisterModel(new(apis.TGdAccessLogMonth7)) orm.RegisterModel(new(apis.TGdAccessLogMonth8)) orm.RegisterModel(new(apis.TGdAccessLogMonth9)) orm.RegisterModel(new(apis.TGdAccessLogMonth10)) orm.RegisterModel(new(apis.TGdAccessLogMonth11)) orm.RegisterModel(new(apis.TGdAccessLogMonth12)) orm.RegisterModel(new(apis.TGdThirdpartLogMonth1)) orm.RegisterModel(new(apis.TGdThirdpartLogMonth2)) orm.RegisterModel(new(apis.TGdThirdpartLogMonth3)) orm.RegisterModel(new(apis.TGdThirdpartLogMonth4)) orm.RegisterModel(new(apis.TGdThirdpartLogMonth5)) orm.RegisterModel(new(apis.TGdThirdpartLogMonth6)) orm.RegisterModel(new(apis.TGdThirdpartLogMonth7)) orm.RegisterModel(new(apis.TGdThirdpartLogMonth8)) orm.RegisterModel(new(apis.TGdThirdpartLogMonth9)) orm.RegisterModel(new(apis.TGdThirdpartLogMonth10)) orm.RegisterModel(new(apis.TGdThirdpartLogMonth11)) orm.RegisterModel(new(apis.TGdThirdpartLogMonth12)) } // 按计划执行定时任务 // 秒,分钟,小时,日,月,星期几,执行的func。 func TaskInit() { //conf := parser.Conf.Rpc.Cron fmt.Println("bill cron :",config.Conf.BillCreateCron) c := cron.New() //config.Conf.BillCreateCron // 定时每日凌晨启动车辆查询 _ = c.AddFunc(config.Conf.BillCreateCron, func() { accounting.GenerateBill() }) _ = c.AddFunc(config.Conf.BillNotifyCron, func() { accounting.BillNotify() }) _ = c.AddFunc("0 */1 * * * ?", func() { warning.CheckLog() }) c.Start() }