新增获取终端数量统计,任务统计

This commit is contained in:
chy
2025-07-05 14:33:28 +08:00
parent 2dfe6540ae
commit 28bb6c6797
13 changed files with 356 additions and 51 deletions

View File

@ -5,7 +5,12 @@ import "github.com/gogf/gf/v2/frame/g"
type GetOnlineDeviceReq struct {
g.Meta `path:"/statistic/onlineDevice" method:"get" tags:"Backend/Statistic" summary:"(系统、商户、门店)获取门店设备在线列表"`
NetbarAccount string `json:"netbarAccount" v:"required#网吧网关账号不能为空" dc:"网吧网关账号"`
StoreId int64 `json:"storeId" v:"required#门店ID不能为空" dc:"门店ID"`
}
type GetOnlineDeviceRes struct {
Total int64 `json:"total"`
TerminalTotal int64 `json:"terminalTotal"`
OnlineTerminalTotal int64 `json:"onlineTerminalTotal"`
StartTimes int64 `json:"startTimes"`
TaskTimes int64 `json:"taskTimes"`
TaskCompletedTotal int64 `json:"taskCompletedTotal"`
}

View File

@ -2,19 +2,33 @@ package statistic
import (
"context"
"fmt"
"github.com/gogf/gf/v2/frame/g"
"server/internal/consts"
_ "fmt"
_ "github.com/gogf/gf/v2/frame/g"
"server/internal/model"
"server/internal/service"
"server/api/statistic/v1"
)
func (c *ControllerV1) GetOnlineDevice(ctx context.Context, req *v1.GetOnlineDeviceReq) (res *v1.GetOnlineDeviceRes, err error) {
get, err := g.Redis().Get(ctx, fmt.Sprintf(consts.NetbarOnlineNumberKey, req.NetbarAccount))
//get, err := g.Redis().Get(ctx, fmt.Sprintf(consts.NetbarOnlineNumberKey, req.NetbarAccount))
//if err != nil {
// return nil, err
//}
out, err := service.Statistic().GetOnlineDevice(ctx, &model.GetOnlineDeviceIn{
NetbarAccount: req.NetbarAccount,
StoreId: req.StoreId,
})
if err != nil {
return nil, err
}
return &v1.GetOnlineDeviceRes{
Total: get.Int64(),
OnlineTerminalTotal: out.OnlineTerminalTotal,
StartTimes: out.StartTimes,
TaskCompletedTotal: out.TaskCompletedTotal,
TaskTimes: out.TaskTimes,
TerminalTotal: out.TerminalTotal,
}, nil
}

View File

@ -0,0 +1,107 @@
// ==========================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// StoreClientSessionsDao is the data access object for the table store_client_sessions.
type StoreClientSessionsDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO.
columns StoreClientSessionsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
}
// StoreClientSessionsColumns defines and stores column names for the table store_client_sessions.
type StoreClientSessionsColumns struct {
Id string // 记录ID
StoreId string // 所属门店ID
ClientId string // 客户机ID
AreaId string // 所属区域ID
XyUserId string // 系统唯一用户ID
LevelId string // 会员等级ID如0表示临时卡
LevelName string // 会员等级名称
StartTime string // 上机时间
EndTime string // 下机时间
UsedTime string // 使用时长(分钟)
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
DeletedAt string // 软删除时间戳
AreaName string //
UserId string // 用户 id
}
// storeClientSessionsColumns holds the columns for the table store_client_sessions.
var storeClientSessionsColumns = StoreClientSessionsColumns{
Id: "id",
StoreId: "store_id",
ClientId: "client_id",
AreaId: "area_id",
XyUserId: "xy_user_id",
LevelId: "level_id",
LevelName: "level_name",
StartTime: "start_time",
EndTime: "end_time",
UsedTime: "used_time",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
DeletedAt: "deleted_at",
AreaName: "area_name",
UserId: "user_id",
}
// NewStoreClientSessionsDao creates and returns a new DAO object for table data access.
func NewStoreClientSessionsDao(handlers ...gdb.ModelHandler) *StoreClientSessionsDao {
return &StoreClientSessionsDao{
group: "default",
table: "store_client_sessions",
columns: storeClientSessionsColumns,
handlers: handlers,
}
}
// DB retrieves and returns the underlying raw database management object of the current DAO.
func (dao *StoreClientSessionsDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of the current DAO.
func (dao *StoreClientSessionsDao) Table() string {
return dao.table
}
// Columns returns all column names of the current DAO.
func (dao *StoreClientSessionsDao) Columns() StoreClientSessionsColumns {
return dao.columns
}
// Group returns the database configuration group name of the current DAO.
func (dao *StoreClientSessionsDao) Group() string {
return dao.group
}
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoreClientSessionsDao) Ctx(ctx context.Context) *gdb.Model {
model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rolls back the transaction and returns the error if function f returns a non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note: Do not commit or roll back the transaction in function f,
// as it is automatically handled by this function.
func (dao *StoreClientSessionsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@ -25,9 +25,7 @@ type StoreNetfeeAreaLevelColumns struct {
StoreId string // 门店ID
RewardId string // 奖励IDrewards表主键
AreaId string // 区域ID外部系统
AreaName string // 区域名称
MemberLevelId string // 会员等级ID外部系统
MemberLevelName string // 会员等级名称
PriceData string // 7x24价格矩阵
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
@ -40,9 +38,7 @@ var storeNetfeeAreaLevelColumns = StoreNetfeeAreaLevelColumns{
StoreId: "store_id",
RewardId: "reward_id",
AreaId: "area_id",
AreaName: "area_name",
MemberLevelId: "member_level_id",
MemberLevelName: "member_level_name",
PriceData: "price_data",
CreatedAt: "created_at",
UpdatedAt: "updated_at",

View File

@ -0,0 +1,22 @@
// =================================================================================
// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed.
// =================================================================================
package dao
import (
"server/internal/dao/internal"
)
// storeClientSessionsDao is the data access object for the table store_client_sessions.
// You can define custom methods on it to extend its functionality as needed.
type storeClientSessionsDao struct {
*internal.StoreClientSessionsDao
}
var (
// StoreClientSessions is a globally accessible object for table store_client_sessions operations.
StoreClientSessions = storeClientSessionsDao{internal.NewStoreClientSessionsDao()}
)
// Add your custom methods and functionality below.

View File

@ -13,6 +13,7 @@ import (
_ "server/internal/logic/reward"
_ "server/internal/logic/rewardType"
_ "server/internal/logic/role"
_ "server/internal/logic/statistic"
_ "server/internal/logic/store"
_ "server/internal/logic/storeAdmin"
_ "server/internal/logic/storeDesktopSetting"

View File

@ -0,0 +1,47 @@
package statistic
import (
"context"
"server/internal/dao"
"server/internal/model"
"server/internal/model/do"
"server/internal/service"
"server/utility/ecode"
)
type sStatistic struct {
}
func New() service.IStatistic {
return &sStatistic{}
}
func init() {
service.RegisterStatistic(New())
}
func (s *sStatistic) GetOnlineDevice(ctx context.Context, in *model.GetOnlineDeviceIn) (out *model.GetOnlineDeviceOut, err error) {
storeId, err := dao.Stores.Ctx(ctx).Fields(dao.Stores.Columns().Id).Where(do.Stores{NetbarAccount: in.NetbarAccount}).Value()
if storeId.Int() == 0 {
return nil, ecode.Fail.Sub("门店不存在")
}
if err != nil {
return nil, ecode.Fail.Sub("查询门店 id失败")
}
var data model.GetOnlineDeviceOut
if err = dao.StoreClients.Ctx(ctx).Where(do.StoreClients{StoreId: storeId}).Fields("count(*) as terminal_total,count(case when status = 3 then 1 end) as online_terminal_total").Scan(&data); err != nil {
return nil, ecode.Fail.Sub("终端数量统计失败")
}
if err = dao.StoreClientSessions.Ctx(ctx).Where(do.StoreClientSessions{StoreId: storeId}).Fields("count(*) as start_times").Scan(&data); err != nil {
return nil, ecode.Fail.Sub("终端启动次数统计失败")
}
if err = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{StoreId: storeId}).Fields("count(*) as task_times,count(case when status = 2 then 1 end) as task_completed_total").Scan(&data); err != nil {
return nil, ecode.Fail.Sub("任务相关统计失败")
}
return &data, nil
}

View File

@ -0,0 +1,30 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// StoreClientSessions is the golang structure of table store_client_sessions for DAO operations like Where/Data.
type StoreClientSessions struct {
g.Meta `orm:"table:store_client_sessions, do:true"`
Id interface{} // 记录ID
StoreId interface{} // 所属门店ID
ClientId interface{} // 客户机ID
AreaId interface{} // 所属区域ID
XyUserId interface{} // 系统唯一用户ID
LevelId interface{} // 会员等级ID如0表示临时卡
LevelName interface{} // 会员等级名称
StartTime *gtime.Time // 上机时间
EndTime *gtime.Time // 下机时间
UsedTime interface{} // 使用时长(分钟)
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 更新时间
DeletedAt *gtime.Time // 软删除时间戳
AreaName interface{} //
UserId interface{} // 用户 id
}

View File

@ -16,9 +16,7 @@ type StoreNetfeeAreaLevel struct {
StoreId interface{} // 门店ID
RewardId interface{} // 奖励IDrewards表主键
AreaId interface{} // 区域ID外部系统
AreaName interface{} // 区域名称
MemberLevelId interface{} // 会员等级ID外部系统
MemberLevelName interface{} // 会员等级名称
PriceData interface{} // 7x24价格矩阵
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 更新时间

View File

@ -0,0 +1,28 @@
// =================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// StoreClientSessions is the golang structure for table store_client_sessions.
type StoreClientSessions struct {
Id int64 `json:"id" orm:"id" description:"记录ID"` // 记录ID
StoreId int64 `json:"storeId" orm:"store_id" description:"所属门店ID"` // 所属门店ID
ClientId int64 `json:"clientId" orm:"client_id" description:"客户机ID"` // 客户机ID
AreaId int64 `json:"areaId" orm:"area_id" description:"所属区域ID"` // 所属区域ID
XyUserId string `json:"xyUserId" orm:"xy_user_id" description:"系统唯一用户ID"` // 系统唯一用户ID
LevelId int `json:"levelId" orm:"level_id" description:"会员等级ID如0表示临时卡"` // 会员等级ID如0表示临时卡
LevelName string `json:"levelName" orm:"level_name" description:"会员等级名称"` // 会员等级名称
StartTime *gtime.Time `json:"startTime" orm:"start_time" description:"上机时间"` // 上机时间
EndTime *gtime.Time `json:"endTime" orm:"end_time" description:"下机时间"` // 下机时间
UsedTime int `json:"usedTime" orm:"used_time" description:"使用时长(分钟)"` // 使用时长(分钟)
CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间戳"` // 软删除时间戳
AreaName string `json:"areaName" orm:"area_name" description:""` //
UserId int `json:"userId" orm:"user_id" description:"用户 id"` // 用户 id
}

View File

@ -14,9 +14,7 @@ type StoreNetfeeAreaLevel struct {
StoreId int64 `json:"storeId" orm:"store_id" description:"门店ID"` // 门店ID
RewardId int64 `json:"rewardId" orm:"reward_id" description:"奖励IDrewards表主键"` // 奖励IDrewards表主键
AreaId int64 `json:"areaId" orm:"area_id" description:"区域ID外部系统"` // 区域ID外部系统
AreaName string `json:"areaName" orm:"area_name" description:"区域名称"` // 区域名称
MemberLevelId int64 `json:"memberLevelId" orm:"member_level_id" description:"会员等级ID外部系统"` // 会员等级ID外部系统
MemberLevelName string `json:"memberLevelName" orm:"member_level_name" description:"会员等级名称"` // 会员等级名称
PriceData string `json:"priceData" orm:"price_data" description:"7x24价格矩阵"` // 7x24价格矩阵
CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间

View File

@ -0,0 +1,27 @@
package model
import "github.com/gogf/gf/v2/os/gtime"
type StoreClients struct {
Id int64 `json:"id" orm:"id" description:"客户机ID"` // 客户机ID
StoreId int64 `json:"storeId" orm:"store_id" description:"所属门店ID"` // 所属门店ID
ClientName string `json:"clientName" orm:"client_name" description:"客户机名称"` // 客户机名称
Status int `json:"status" orm:"status" description:"状态1=空闲2=禁用3=上机中等"` // 状态1=空闲2=禁用3=上机中等
AreaId int64 `json:"areaId" orm:"area_id" description:"所属区域ID"` // 所属区域ID
CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:""` //
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:""` //
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:""` //
}
type GetOnlineDeviceOut struct {
TerminalTotal int64 `json:"terminalTotal"`
OnlineTerminalTotal int64 `json:"onlineTerminalTotal"`
StartTimes int64 `json:"startTimes"`
TaskTimes int64 `json:"taskTimes"`
TaskCompletedTotal int64 `json:"taskCompletedTotal"`
}
type GetOnlineDeviceIn struct {
NetbarAccount string `json:"netbarAccount"`
StoreId int64 `json:"storeId"`
}

View File

@ -0,0 +1,32 @@
// ================================================================================
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
import (
"context"
"server/internal/model"
)
type (
IStatistic interface {
GetOnlineDevice(ctx context.Context, in *model.GetOnlineDeviceIn) (out *model.GetOnlineDeviceOut, err error)
}
)
var (
localStatistic IStatistic
)
func Statistic() IStatistic {
if localStatistic == nil {
panic("implement not found for interface IStatistic, forgot register?")
}
return localStatistic
}
func RegisterStatistic(i IStatistic) {
localStatistic = i
}