diff --git a/api/consts/consts.go b/api/consts/consts.go index 4b901769..7b005ce9 100644 --- a/api/consts/consts.go +++ b/api/consts/consts.go @@ -72,3 +72,9 @@ const ProductionConfigPath = PackageRootPath + "/etc/mix/mix-prod.yaml" const LocalConfigPath = "/Users/erwin/wishpal/wishpal-ironfan/etc/mix/mix-local.yaml" const ReservedUserIdRegexesConfig = PackageRootPath + "/etc/mix/resource/reg_reserved_user_id_config.xml" + +// H5调用路径 +const H5CallUrl = "/api/streamer/list_ext_by_user_id" + +// 应用上线时间,2024-01-02 14:00:00 +const AppEnterProductionTime = 1704175200 diff --git a/api/errcode/errcode.go b/api/errcode/errcode.go index b61e493f..7f3383e8 100644 --- a/api/errcode/errcode.go +++ b/api/errcode/errcode.go @@ -130,6 +130,9 @@ var ErrCodeMsgMap = map[ErrCode]string{ ErrCodeVeriCodeSendTimesSrvFail: "验证码频次表服务错误", ErrCodeVeriCodeSendTimesNotExist: "验证码频次表不存在", ErrCodeVeriCodeSendTimesReachedDailyUpperbound: "验证码发送次数已达每日上限", + + ErrCodeDailyStatementSrvFail: "每日报表表服务错误", + ErrCodeDailyStatementNotExist: "每日报表表不存在", } const ( @@ -310,6 +313,11 @@ const ( ErrCodeVeriCodeSendTimesNotExist ErrCode = -25002 // 验证码频次表不存在 ErrCodeVeriCodeSendTimesReachedDailyUpperbound ErrCode = -25003 // 验证码发送次数已达每日上限 + // DailyStatement: 26xxx + ErrCodeDailyStatementSrvOk ErrCode = ErrCodeOk + ErrCodeDailyStatementSrvFail ErrCode = -26001 // 每日报表表服务错误 + ErrCodeDailyStatementNotExist ErrCode = -26002 // 每日报表表不存在 + // Media: 60xxx ErrCodeMediaSrvOk ErrCode = ErrCodeOk ErrCodeMediaSrvFail ErrCode = -60001 // 媒体服务错误 diff --git a/api/proto/daily_statement/proto/daily_statement_op.go b/api/proto/daily_statement/proto/daily_statement_op.go new file mode 100644 index 00000000..0421261f --- /dev/null +++ b/api/proto/daily_statement/proto/daily_statement_op.go @@ -0,0 +1,68 @@ +package proto + +import ( + "service/api/base" + "service/dbstruct" +) + +// op 创建 +type OpCreateReq struct { + base.BaseRequest + *dbstruct.DailyStatement +} + +type OpCreateData struct { +} + +type OpCreateResp struct { + base.BaseResponse + Data *OpCreateData `json:"data"` +} + +// op 删除 +type OpDeleteReq struct { + base.BaseRequest + Id int64 `json:"id"` +} + +type OpDeleteData struct { +} + +type OpDeleteResp struct { + base.BaseResponse + Data *OpDeleteData `json:"data"` +} + +// op 更新 +type OpUpdateReq struct { + base.BaseRequest + *dbstruct.DailyStatement +} + +type OpUpdateData struct { +} + +type OpUpdateResp struct { + base.BaseResponse + Data *OpUpdateData `json:"data"` +} + +// op 列表 +type OpListReq struct { + base.BaseRequest + CtUpperBound *int64 `json:"ct_upper_bound"` + CtLowerBound *int64 `json:"ct_lower_bound"` + Offset int `json:"offset"` + Limit int `json:"limit"` +} + +type OpListData struct { + List []*dbstruct.DailyStatement `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` +} + +type OpListResp struct { + base.BaseResponse + Data *OpListData `json:"data"` +} diff --git a/api/proto/vas/proto/vas.go b/api/proto/vas/proto/vas.go index e25dc3e2..ffba78ad 100644 --- a/api/proto/vas/proto/vas.go +++ b/api/proto/vas/proto/vas.go @@ -79,3 +79,11 @@ type GetCHListData struct { Offset int `json:"offset"` More int `json:"more"` } + +// 订单查询 +type GetOrderByStatusReq struct { + base.BaseRequest + OrderStatuses []int32 `json:"order_statuses"` + CtStart *int64 `json:"ct_start"` + CtEnd *int64 `json:"ct_end"` +} diff --git a/app/mix/cmd/main.go b/app/mix/cmd/main.go index ae796b64..caeaa0d7 100644 --- a/app/mix/cmd/main.go +++ b/app/mix/cmd/main.go @@ -69,11 +69,13 @@ func main() { service.DefaultService = service.NewService() service.DefaultConfigService = service.NewConfigService() service.DefaultCronService = service.NewCronService() + service.DefaultScriptsService = service.NewScriptsService() err = service.DefaultService.Init(cfg) if err != nil { msg := fmt.Sprintf("Service init fail, err: %v", err) PrintAndExit(msg) } + service.DefaultCronService.ReadLoggerConfig(cfg.Log) // 连接到图像审核任务 service.DefaultService.ConnectToImageAudit() diff --git a/app/mix/controller/daily_statement_op.go b/app/mix/controller/daily_statement_op.go new file mode 100644 index 00000000..d0c3d474 --- /dev/null +++ b/app/mix/controller/daily_statement_op.go @@ -0,0 +1,37 @@ +package controller + +import ( + "service/api/consts" + "service/api/errcode" + daily_statementproto "service/api/proto/daily_statement/proto" + "service/app/mix/service" + "service/bizcommon/util" + "service/library/logger" + + "github.com/gin-gonic/gin" +) + +func OpGetDailyStatementList(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*daily_statementproto.OpListReq) + + //设置默认页长 + if req.Limit == 0 { + req.Limit = consts.DefaultPageSize + } + + list, ec := service.DefaultService.OpGetDailyStatementList(ctx, req) + if ec != errcode.ErrCodeDailyStatementSrvOk { + logger.Error("OpGetDailyStatementList fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + data := &daily_statementproto.OpListData{ + List: list, + Offset: req.Offset + len(list), + } + if len(list) >= req.Limit { + data.More = 1 + } + ReplyOk(ctx, data) +} diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index 4bc372e3..3eb5c1db 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -23,6 +23,7 @@ import ( callhistoryproto "service/api/proto/callhistory/proto" contact_customer_serviceproto "service/api/proto/contact_customer_service/proto" contact_customer_service_sessionproto "service/api/proto/contact_customer_service_session/proto" + daily_statementproto "service/api/proto/daily_statement/proto" feedbackproto "service/api/proto/feedback/proto" footprintproto "service/api/proto/footprint/proto" loginproto "service/api/proto/login/proto" @@ -354,9 +355,13 @@ func Init(r *gin.Engine) { opSupportWxIdGroup.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetSupportWxIdList) // 上传媒体失败配置 - opUploadMediaFailConfig := r.Group("/op/upload_media_fail_config", PrepareToC()) + opUploadMediaFailConfig := r.Group("/op/upload_media_fail_config", PrepareOp()) opUploadMediaFailConfig.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), OpGetUploadMediaFailConfigList) + // 每日报表表 + opDailyStatementGroup := r.Group("/op/daily_statement", PrepareOp()) + opDailyStatementGroup.POST("list", middleware.JSONParamValidator(daily_statementproto.OpListReq{}), OpGetDailyStatementList) + // 账号相关 //accountGroup := r.Group("/account") diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index 04f3194e..5f8b81d2 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -18,6 +18,7 @@ import ( callhistoryproto "service/api/proto/callhistory/proto" contact_customer_service_proto "service/api/proto/contact_customer_service/proto" contact_customer_service_sessionproto "service/api/proto/contact_customer_service_session/proto" + daily_statementproto "service/api/proto/daily_statement/proto" feedbackproto "service/api/proto/feedback/proto" footprintproto "service/api/proto/footprint/proto" imageaudittaskproto "service/api/proto/imageaudittask/proto" @@ -139,6 +140,9 @@ const ( DBContactCustomerServiceSession = "contact_customer_service_session" COLContactCustomerServiceSession = "contact_customer_service_session" + + DBDailyStatement = "daily_statement" + COLDailyStatement = "daily_statement" ) // 商品表 @@ -320,6 +324,11 @@ func (m *Mongo) getColContactCustomerServiceSession() *qmgo.Collection { return m.clientMix.Database(DBContactCustomerServiceSession).Collection(COLContactCustomerServiceSession) } +// 每日报表表表 +func (m *Mongo) getColDailyStatement() *qmgo.Collection { + return m.clientMix.Database(DBDailyStatement).Collection(COLDailyStatement) +} + // 商品相关 func (m *Mongo) CreateProduct(ctx *gin.Context, product *dbstruct.Product) error { col := m.getColProduct() @@ -2660,3 +2669,67 @@ func (m *Mongo) GetContactCustomerServiceSessionList(ctx *gin.Context, req *cont } return list, err } + +// 每日报表表相关 +func (m *Mongo) CreateDailyStatement(ctx *gin.Context, daily_statement *dbstruct.DailyStatement) error { + col := m.getColDailyStatement() + _, err := col.InsertOne(ctx, daily_statement) + return err +} + +func (m *Mongo) UpdateDailyStatement(ctx *gin.Context, daily_statement *dbstruct.DailyStatement) error { + col := m.getColDailyStatement() + set := util.EntityToM(daily_statement) + set["ut"] = time.Now().Unix() + up := qmgo.M{ + "$set": set, + } + err := col.UpdateId(ctx, daily_statement.Id, up) + return err +} + +func (m *Mongo) DeleteDailyStatement(ctx *gin.Context, id int64) error { + col := m.getColDailyStatement() + update := qmgo.M{ + "$set": qmgo.M{ + "del_flag": 1, + }, + } + err := col.UpdateId(ctx, id, update) + return err +} + +func (m *Mongo) GetDailyStatementList(ctx *gin.Context, req *daily_statementproto.OpListReq) ([]*dbstruct.DailyStatement, error) { + list := make([]*dbstruct.DailyStatement, 0) + col := m.getColDailyStatement() + query := qmgo.M{ + "del_flag": 0, + } + + filterInClause := []qmgo.M{} + if req.CtLowerBound != nil { + filterInClause = append(filterInClause, qmgo.M{ + "start_time": qmgo.M{ + "$gte": util.DerefInt64(req.CtLowerBound), + }, + }) + } + if req.CtUpperBound != nil { + filterInClause = append(filterInClause, qmgo.M{ + "end_time": qmgo.M{ + "$lte": util.DerefInt64(req.CtUpperBound), + }, + }) + } + + if len(filterInClause) > 0 { + query["$and"] = filterInClause + } + + err := col.Find(ctx, query).Sort("-ct").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) + if err == qmgo.ErrNoSuchDocuments { + err = nil + return list, err + } + return list, err +} diff --git a/app/mix/dao/mysql.go b/app/mix/dao/mysql.go index f147ce47..8b433e68 100644 --- a/app/mix/dao/mysql.go +++ b/app/mix/dao/mysql.go @@ -3,15 +3,17 @@ package dao import ( "errors" "fmt" - "github.com/gin-gonic/gin" - "github.com/jmoiron/sqlx" - goproto "google.golang.org/protobuf/proto" "service/app/mix/conf" "service/bizcommon/util" "service/dbstruct" "service/library/logger" "service/library/mysqldb" + "strings" "time" + + "github.com/gin-gonic/gin" + "github.com/jmoiron/sqlx" + goproto "google.golang.org/protobuf/proto" ) type Mysql struct { @@ -532,3 +534,42 @@ func (m *Mysql) GetUCHList(ctx *gin.Context, tx *sqlx.Tx, mid int64, typ int32, } return } + +// 获取订单 +func (m *Mysql) GetOrderCountGroupByStatus(ctx *gin.Context, tx *sqlx.Tx, orderStatuses []int32, ctStart *int64, ctEnd *int64) (list []*dbstruct.VasOrderStatusCount, err error) { + var sql strings.Builder + var args []interface{} + sql.WriteString(fmt.Sprintf("select order_status, count(1) as count from %s where 1 = 1", TableOrder)) + + if ctStart != nil { + sql.WriteString(" and ct >= ?") + args = append(args, util.DerefInt64(ctStart)) + } + if ctEnd != nil { + sql.WriteString(" and ct <= ?") + args = append(args, util.DerefInt64(ctEnd)) + } + if len(orderStatuses) > 0 { + inClause := strings.Builder{} + inClause.WriteString("?") + args = append(args, orderStatuses[0]) + for i := 1; i < len(orderStatuses); i++ { + inClause.WriteString(",?") + args = append(args, orderStatuses[i]) + } + sql.WriteString(fmt.Sprintf(" and order_status in (%s)", inClause.String())) + } + sql.WriteString(" group by order_status") + + list = make([]*dbstruct.VasOrderStatusCount, 0) + if tx != nil { + err = tx.SelectContext(ctx, &list, sql.String(), args...) + } else { + db := m.getDBVas() + err = db.SelectContext(ctx, &list, sql.String(), args...) + } + if err != nil { + return + } + return +} diff --git a/app/mix/service/cronservice.go b/app/mix/service/cronservice.go index 964e16cc..307c7986 100644 --- a/app/mix/service/cronservice.go +++ b/app/mix/service/cronservice.go @@ -1,10 +1,16 @@ package service import ( + "fmt" "service/api/consts" "service/api/errcode" - "service/api/proto/streamer/proto" + accountproto "service/api/proto/account/proto" + daily_statementproto "service/api/proto/daily_statement/proto" + streamerproto "service/api/proto/streamer/proto" + vasproto "service/api/proto/vas/proto" "service/bizcommon/util" + "service/dbstruct" + "service/library/configcenter" "service/library/contentaudit/imageaudit" "service/library/contentaudit/textaudit" "service/library/logger" @@ -13,6 +19,7 @@ import ( "github.com/gin-gonic/gin" "github.com/go-co-op/gocron" + goproto "google.golang.org/protobuf/proto" ) var ( @@ -20,17 +27,23 @@ var ( ) type CronService struct { + fileAbsPath string } func NewCronService() *CronService { return new(CronService) } +func (s *CronService) ReadLoggerConfig(config configcenter.LoggerConfig) { + s.fileAbsPath = config.FileAbsPath +} + func (s *CronService) Run() { s.ReloadRecommList() s.ImageAuditBatch() s.TextAuditBatch() s.ClearVeriCodeSendTimes() + s.CreateDailyStatement() } func (s *CronService) ReloadRecommList() { @@ -45,7 +58,7 @@ func (s *CronService) ReloadRecommList() { // logger.Error("OpGetAccountRelationCount fail, ec: %v", ec) // scheduler.Stop() // } - list, ec := DefaultService.OpGetStreamerList(ctx, &proto.OpListReq{ + list, ec := DefaultService.OpGetStreamerList(ctx, &streamerproto.OpListReq{ Sort: "-fans", }) if ec != errcode.ErrCodeAccountRelationSrvOk { @@ -95,3 +108,72 @@ func (s *CronService) ClearVeriCodeSendTimes() { }) scheduler.StartAsync() } + +// 统计每日报表 +func (s *CronService) CreateDailyStatement() { + loc, _ := time.LoadLocation("Asia/Shanghai") + scheduler := gocron.NewScheduler(loc) + + scheduler.CronWithSeconds("0 0 * * * *").Do(func() { + + //拿到现在的时间戳 + nowTimeStamp := util.GetHourStartTimeStamp(time.Now()) + + //获取上个小时时间段 + startTimeStamp := nowTimeStamp - int64(60*60) + endTimeStamp := nowTimeStamp - int64(1) + starttime := time.Unix(startTimeStamp, 0) + endtime := time.Unix(endTimeStamp, 0) + + //获取H5接口访问量 + logpath := fmt.Sprintf("%v_%02d%02d%02d.Global", s.fileAbsPath, starttime.Year(), starttime.Month(), starttime.Day()) + count, err := DefaultScriptsService.QueryCallCount(consts.H5CallUrl, logpath) + if err != nil { + logger.Error("query h5 call count fail : %v", err) + } + + //获取用户总量 + accountCount, err := _DefaultAccount.OpCount(&gin.Context{}, &accountproto.OpCountReq{ + CtLowerBound: goproto.Int64(int64(consts.AppEnterProductionTime)), + }) + if err != nil { + logger.Error("_DefaultAccount OpCount fail : %v", err) + } + + //获取订单总量 + orderCounts, err := _DefaultVas.GetOrderCountGroupByStatus(&gin.Context{}, &vasproto.GetOrderByStatusReq{ + CtStart: goproto.Int64(consts.AppEnterProductionTime), + CtEnd: nil, + }) + if err != nil { + logger.Error("_DefaultVas GetOrderCountByStatus fail : %v", err) + } + + finishedOrderCount := int32(0) + allOrderCount := int32(0) + for _, orderCount := range orderCounts { + if util.DerefInt32(orderCount.OrderStatus) != 0 { + finishedOrderCount += util.DerefInt32(orderCount.Count) + } + allOrderCount += util.DerefInt32(orderCount.Count) + } + + dailyStatement := &dbstruct.DailyStatement{ + H5CallCount: goproto.Int64(int64(count)), + RegisteredUserCount: goproto.Int64(accountCount), + OrderCreatedCount: goproto.Int64(int64(allOrderCount)), + OrderFinishedCount: goproto.Int64(int64(finishedOrderCount)), + StartTime: goproto.Int64(startTimeStamp), + EndTime: goproto.Int64(endTimeStamp), + } + err = _DefaultDailyStatement.OpCreate(&gin.Context{}, &daily_statementproto.OpCreateReq{ + DailyStatement: dailyStatement, + }) + if err != nil { + logger.Error("_DefaultDailyStatement OpCreate fail : %v", err) + } + + logger.Info("%v - %v statement data has created...", starttime, endtime) + }) + scheduler.StartAsync() +} diff --git a/app/mix/service/logic/daily_statement.go b/app/mix/service/logic/daily_statement.go new file mode 100644 index 00000000..7973061f --- /dev/null +++ b/app/mix/service/logic/daily_statement.go @@ -0,0 +1,65 @@ +package logic + +import ( + "service/api/consts" + daily_statementproto "service/api/proto/daily_statement/proto" + "service/app/mix/dao" + "service/dbstruct" + "service/library/idgenerator" + "service/library/logger" + "time" + + "github.com/gin-gonic/gin" + goproto "google.golang.org/protobuf/proto" +) + +type DailyStatement struct { + store *dao.Store +} + +func NewDailyStatement(store *dao.Store) (a *DailyStatement) { + a = &DailyStatement{ + store: store, + } + return +} + +func (p *DailyStatement) OpCreate(ctx *gin.Context, req *daily_statementproto.OpCreateReq) error { + req.DailyStatement.Id = goproto.Int64(idgenerator.GenDailyStatementId()) + req.DailyStatement.Ct = goproto.Int64(time.Now().Unix()) + req.DailyStatement.Ut = goproto.Int64(time.Now().Unix()) + req.DailyStatement.DelFlag = goproto.Int64(consts.Exist) + err := p.store.CreateDailyStatement(ctx, req.DailyStatement) + if err != nil { + logger.Error("CreateDailyStatement fail, err: %v", err) + return err + } + return nil +} + +func (p *DailyStatement) OpUpdate(ctx *gin.Context, req *daily_statementproto.OpUpdateReq) error { + err := p.store.UpdateDailyStatement(ctx, req.DailyStatement) + if err != nil { + logger.Error("UpdateDailyStatement fail, err: %v", err) + return err + } + return nil +} + +func (p *DailyStatement) OpDelete(ctx *gin.Context, id int64) error { + err := p.store.DeleteDailyStatement(ctx, id) + if err != nil { + logger.Error("DeleteDailyStatement fail, err: %v", err) + return err + } + return nil +} + +func (p *DailyStatement) OpList(ctx *gin.Context, req *daily_statementproto.OpListReq) ([]*dbstruct.DailyStatement, error) { + list, err := p.store.GetDailyStatementList(ctx, req) + if err != nil { + logger.Error("GetDailyStatementList fail, err: %v", err) + return make([]*dbstruct.DailyStatement, 0), err + } + return list, nil +} diff --git a/app/mix/service/logic/vas.go b/app/mix/service/logic/vas.go index bfc7ee7c..7e119882 100644 --- a/app/mix/service/logic/vas.go +++ b/app/mix/service/logic/vas.go @@ -4,10 +4,6 @@ import ( "database/sql" "errors" "fmt" - "github.com/gin-gonic/gin" - "github.com/jmoiron/sqlx" - "github.com/samber/lo" - goproto "google.golang.org/protobuf/proto" "service/api/base" "service/api/errs" vasproto "service/api/proto/vas/proto" @@ -19,6 +15,11 @@ import ( "service/library/logger" "service/library/payclients/alipaycli" "time" + + "github.com/gin-gonic/gin" + "github.com/jmoiron/sqlx" + "github.com/samber/lo" + goproto "google.golang.org/protobuf/proto" ) type Vas struct { @@ -1671,3 +1672,7 @@ func (v *Vas) AlipayCallback(ctx *gin.Context, p *vasproto.AlipayCallbackParamIn func (v *Vas) GetCoinOrderById(ctx *gin.Context, id string) (*dbstruct.CoinOrder, error) { return v.store.GetCoinOrderById(ctx, nil, id) } + +func (v *Vas) GetOrderCountGroupByStatus(ctx *gin.Context, req *vasproto.GetOrderByStatusReq) ([]*dbstruct.VasOrderStatusCount, error) { + return v.store.GetOrderCountGroupByStatus(ctx, nil, req.OrderStatuses, req.CtStart, req.CtEnd) +} diff --git a/app/mix/service/scripts_service.go b/app/mix/service/scripts_service.go new file mode 100644 index 00000000..47b745ed --- /dev/null +++ b/app/mix/service/scripts_service.go @@ -0,0 +1,32 @@ +package service + +import ( + "fmt" + "os/exec" + "service/library/logger" + "strconv" +) + +var ( + DefaultScriptsService *ScriptsService +) + +type ScriptsService struct { +} + +func NewScriptsService() *ScriptsService { + return new(ScriptsService) +} + +// 放置一些执行服务器脚本的service +func (s *ScriptsService) QueryCallCount(url string, logpath string) (count int, err error) { + cmdStr := fmt.Sprintf("grep -c %v %v", url, logpath) + cmd := exec.Command(cmdStr) + out, err := cmd.Output() + if err != nil { + logger.Error("could not run command: %v", err) + return + } + count, err = strconv.Atoi(string(out)) + return +} diff --git a/app/mix/service/service.go b/app/mix/service/service.go index d64fa962..40b5f8b6 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -14,6 +14,7 @@ import ( catalogproto "service/api/proto/catalog/proto" contact_customer_service_proto "service/api/proto/contact_customer_service/proto" contact_customer_service_sessionproto "service/api/proto/contact_customer_service_session/proto" + daily_statementproto "service/api/proto/daily_statement/proto" feedbackproto "service/api/proto/feedback/proto" footprintproto "service/api/proto/footprint/proto" imageauditproto "service/api/proto/imageaudit/proto" @@ -92,6 +93,7 @@ var ( _DefaultTextAudit *logic.TextAudit _DefaultTextAuditTask *logic.TextAuditTask _DefaultContactCustomerServiceSession *logic.ContactCustomerServiceSession + _DefaultDailyStatement *logic.DailyStatement ) type Service struct { @@ -157,6 +159,7 @@ func (s *Service) Init(c any) (err error) { _DefaultTextAuditTask = logic.NewTextAuditTask(store) _DefaultVas = logic.NewVas(store, _DefaultStreamer) _DefaultContactCustomerServiceSession = logic.NewContactCustomerServiceSession(store) + _DefaultDailyStatement = logic.NewDailyStatement(store) return } @@ -2499,3 +2502,15 @@ func (s *Service) OpGetContactCustomerServiceSessionList(ctx *gin.Context, req * } return } + +// DailyStatement +func (s *Service) OpGetDailyStatementList(ctx *gin.Context, req *daily_statementproto.OpListReq) (list []*dbstruct.DailyStatement, ec errcode.ErrCode) { + ec = errcode.ErrCodeDailyStatementSrvOk + list, err := _DefaultDailyStatement.OpList(ctx, req) + if err != nil { + logger.Error("OpGetDailyStatementList fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeDailyStatementSrvFail + return + } + return +} diff --git a/bizcommon/util/util.go b/bizcommon/util/util.go index 8b540bd8..695df762 100644 --- a/bizcommon/util/util.go +++ b/bizcommon/util/util.go @@ -8,6 +8,7 @@ import ( "reflect" "service/library/logger" "strings" + "time" "github.com/qiniu/qmgo" ) @@ -62,3 +63,14 @@ func UderscoreToUpperCamelCase(s string) string { func Convert2SqlArr(a ...any) string { return strings.Replace(strings.Trim(fmt.Sprint(a), "[]"), " ", ",", -1) } + +// 获取整点时间戳 +func GetHourStartTimeStamp(t time.Time) int64 { + loc, _ := time.LoadLocation("Asia/Shanghai") + timeStr := fmt.Sprintf("%02d-%02d-%02d %02d:00:00", t.Year(), t.Month(), t.Day(), t.Hour()) + duetimecst, err := time.ParseInLocation("2006-1-2 15:04:05", timeStr, loc) + if err != nil { + logger.Error("parse error : %v", err) + } + return duetimecst.Unix() +} diff --git a/codecreate/codecreate.go b/codecreate/codecreate.go index 994fb891..77a1b3d9 100644 --- a/codecreate/codecreate.go +++ b/codecreate/codecreate.go @@ -9,48 +9,48 @@ import ( func main() { genSource := &generator.GenSource{ - EntityName: "ContactCustomerServiceSession", - ModuleName: "contact_customer_service_session", - EntityCNName: "联系客服对话表", - ErrCodeSeq: "24", + EntityName: "DailyStatement", + ModuleName: "daily_statement", + EntityCNName: "每日报表表", + ErrCodeSeq: "26", } generator.CreateFileDirectory(genSource) - // genSource.InPath = consts.EntityInPath - // genSource.OutPath = fmt.Sprintf("%v%v%v.go", consts.RootPath, consts.EntityOutPath, genSource.ModuleName) - // generator.GenerateEntity(genSource) + genSource.InPath = consts.EntityInPath + genSource.OutPath = fmt.Sprintf("%v%v%v.go", consts.RootPath, consts.EntityOutPath, genSource.ModuleName) + generator.GenerateEntity(genSource) - // genSource.InPath = consts.IdGeneratorInPath - // genSource.OutPath = fmt.Sprintf("%v%v%v_idgenerator.go", consts.RootPath, consts.IdgeneratorOutPath, genSource.ModuleName) - // generator.GenerateModule(genSource) + genSource.InPath = consts.IdGeneratorInPath + genSource.OutPath = fmt.Sprintf("%v%v%v_idgenerator.go", consts.RootPath, consts.IdgeneratorOutPath, genSource.ModuleName) + generator.GenerateModule(genSource) - // genSource.InPath = consts.MongoInPath - // genSource.OutPath = fmt.Sprintf("%v%v%v_mongo.go", consts.RootPath, consts.MongoOutPath, genSource.ModuleName) - // generator.GenerateModule(genSource) + genSource.InPath = consts.MongoInPath + genSource.OutPath = fmt.Sprintf("%v%v%v_mongo.go", consts.RootPath, consts.MongoOutPath, genSource.ModuleName) + generator.GenerateModule(genSource) genSource.InPath = consts.ProtoInPath genSource.OutPath = fmt.Sprintf("%v%v%v/proto/%v_op.go", consts.RootPath, consts.ProtoOutPath, genSource.ModuleName, genSource.ModuleName) generator.GenerateModule(genSource) - // genSource.InPath = consts.ServiceInPath - // genSource.OutPath = fmt.Sprintf("%v%v%v.go", consts.RootPath, consts.ServiceOutPath, genSource.ModuleName) - // generator.GenerateModule(genSource) + genSource.InPath = consts.ServiceInPath + genSource.OutPath = fmt.Sprintf("%v%v%v.go", consts.RootPath, consts.ServiceOutPath, genSource.ModuleName) + generator.GenerateModule(genSource) - // genSource.InPath = consts.ServiceCenterInPath - // genSource.OutPath = fmt.Sprintf("%v%v%v_service_center.go", consts.RootPath, consts.ServiceCenterOutPath, genSource.ModuleName) - // generator.GenerateModule(genSource) + genSource.InPath = consts.ServiceCenterInPath + genSource.OutPath = fmt.Sprintf("%v%v%v_service_center.go", consts.RootPath, consts.ServiceCenterOutPath, genSource.ModuleName) + generator.GenerateModule(genSource) - // genSource.InPath = consts.ErrCodeInPath - // genSource.OutPath = fmt.Sprintf("%v%v%v_errcode.go", consts.RootPath, consts.ErrcodeOutPath, genSource.ModuleName) - // generator.GenerateModule(genSource) + genSource.InPath = consts.ErrCodeInPath + genSource.OutPath = fmt.Sprintf("%v%v%v_errcode.go", consts.RootPath, consts.ErrcodeOutPath, genSource.ModuleName) + generator.GenerateModule(genSource) - // genSource.InPath = consts.ControllerInPath - // genSource.OutPath = fmt.Sprintf("%v%v%v_op.go", consts.RootPath, consts.ControllerOutPath, genSource.ModuleName) - // generator.GenerateModule(genSource) + genSource.InPath = consts.ControllerInPath + genSource.OutPath = fmt.Sprintf("%v%v%v_op.go", consts.RootPath, consts.ControllerOutPath, genSource.ModuleName) + generator.GenerateModule(genSource) - // genSource.InPath = consts.ControllerCenterInPath - // genSource.OutPath = fmt.Sprintf("%v%v%v_controller_center.go", consts.RootPath, consts.ControllerCenterOutPath, genSource.ModuleName) - // generator.GenerateModule(genSource) + genSource.InPath = consts.ControllerCenterInPath + genSource.OutPath = fmt.Sprintf("%v%v%v_controller_center.go", consts.RootPath, consts.ControllerCenterOutPath, genSource.ModuleName) + generator.GenerateModule(genSource) } diff --git a/codecreate/resource/EntityDefine.xlsx b/codecreate/resource/EntityDefine.xlsx index f384b89b..9be680f0 100644 Binary files a/codecreate/resource/EntityDefine.xlsx and b/codecreate/resource/EntityDefine.xlsx differ diff --git a/dbstruct/daily_statement.go b/dbstruct/daily_statement.go new file mode 100644 index 00000000..3d224005 --- /dev/null +++ b/dbstruct/daily_statement.go @@ -0,0 +1,15 @@ +package dbstruct + +type DailyStatement struct { + Id *int64 `json:"id" bson:"_id"` // 每日报表id + H5CallCount *int64 `json:"h5_call_count" bson:"h5_call_count"` // H5接口调用总量 + RegisteredUserCount *int64 `json:"registered_user_count" bson:"registered_user_count"` // 注册用户总量 + OrderCreatedCount *int64 `json:"order_created_count" bson:"order_created_count"` // 订单创建总量 + OrderFinishedCount *int64 `json:"order_finished_count" bson:"order_finished_count"` // 订单完成总量 + StartTime *int64 `json:"start_time" bson:"start_time"` // 起始时间 + EndTime *int64 `json:"end_time" bson:"end_time"` // 结束时间 + Ct *int64 `json:"ct" bson:"ct"` // 创建时间 + Ut *int64 `json:"ut" bson:"ut"` // 更新时间 + DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记 + +} diff --git a/dbstruct/vas_mysql.go b/dbstruct/vas_mysql.go index eb111966..19960de3 100644 --- a/dbstruct/vas_mysql.go +++ b/dbstruct/vas_mysql.go @@ -653,3 +653,8 @@ func (p *UserVasUnlock) GetOrderId() string { } return "" } + +type VasOrderStatusCount struct { + OrderStatus *int32 `json:"order_status" db:"order_status"` + Count *int32 `json:"count" db:"count"` +} diff --git a/library/idgenerator/genid.go b/library/idgenerator/genid.go index 3718154c..909487c2 100644 --- a/library/idgenerator/genid.go +++ b/library/idgenerator/genid.go @@ -44,6 +44,7 @@ const ( NodeImageAuditTask // node 图像审核任务 NodeTextAudit // node 文字审核 NodeTextAuditTask // node 文字审核任务 + NodeDailyStatement // node 每日报表表 ) func GenIdInt64(node int64) (int64, error) { @@ -190,26 +191,8 @@ func GenContactCustomerServiceId() int64 { return id } -// // imageaudit -// func GenImageAuditId() string { -// id, _ := GenIdString(NodeImageAudit) -// return id -// } - -// // imageaudittask -// func GenImageAuditTaskId() string { -// id, _ := GenIdString(NodeImageAuditTask) -// return id -// } - -// // textaudit -// func GenTextAuditId() string { -// id, _ := GenIdString(NodeTextAudit) -// return id -// } - -// // textaudittask -// func GenTextAuditTaskId() string { -// id, _ := GenIdString(NodeTextAuditTask) -// return id -// } +// daily_statement +func GenDailyStatementId() int64 { + id, _ := GenIdInt64(NodeDailyStatement) + return id +}