diff --git a/api/statistic/v1/statistic.go b/api/statistic/v1/statistic.go index 9062855..478bbfe 100644 --- a/api/statistic/v1/statistic.go +++ b/api/statistic/v1/statistic.go @@ -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"` } diff --git a/internal/controller/statistic/statistic_v1_get_online_device.go b/internal/controller/statistic/statistic_v1_get_online_device.go index 2c2d859..488f02a 100644 --- a/internal/controller/statistic/statistic_v1_get_online_device.go +++ b/internal/controller/statistic/statistic_v1_get_online_device.go @@ -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 } diff --git a/internal/dao/internal/store_client_sessions.go b/internal/dao/internal/store_client_sessions.go new file mode 100644 index 0000000..ce5b91b --- /dev/null +++ b/internal/dao/internal/store_client_sessions.go @@ -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) +} diff --git a/internal/dao/internal/store_netfee_area_level.go b/internal/dao/internal/store_netfee_area_level.go index ffa209a..25e019c 100644 --- a/internal/dao/internal/store_netfee_area_level.go +++ b/internal/dao/internal/store_netfee_area_level.go @@ -21,32 +21,28 @@ type StoreNetfeeAreaLevelDao struct { // StoreNetfeeAreaLevelColumns defines and stores column names for the table store_netfee_area_level. type StoreNetfeeAreaLevelColumns struct { - Id string // 主键ID - StoreId string // 门店ID - RewardId string // 奖励ID(rewards表主键) - AreaId string // 区域ID(外部系统) - AreaName string // 区域名称 - MemberLevelId string // 会员等级ID(外部系统) - MemberLevelName string // 会员等级名称 - PriceData string // 7x24价格矩阵 - CreatedAt string // 创建时间 - UpdatedAt string // 更新时间 - DeletedAt string // 删除时间 + Id string // 主键ID + StoreId string // 门店ID + RewardId string // 奖励ID(rewards表主键) + AreaId string // 区域ID(外部系统) + MemberLevelId string // 会员等级ID(外部系统) + PriceData string // 7x24价格矩阵 + CreatedAt string // 创建时间 + UpdatedAt string // 更新时间 + DeletedAt string // 删除时间 } // storeNetfeeAreaLevelColumns holds the columns for the table store_netfee_area_level. var storeNetfeeAreaLevelColumns = StoreNetfeeAreaLevelColumns{ - Id: "id", - 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", - DeletedAt: "deleted_at", + Id: "id", + StoreId: "store_id", + RewardId: "reward_id", + AreaId: "area_id", + MemberLevelId: "member_level_id", + PriceData: "price_data", + CreatedAt: "created_at", + UpdatedAt: "updated_at", + DeletedAt: "deleted_at", } // NewStoreNetfeeAreaLevelDao creates and returns a new DAO object for table data access. diff --git a/internal/dao/store_client_sessions.go b/internal/dao/store_client_sessions.go new file mode 100644 index 0000000..08528ed --- /dev/null +++ b/internal/dao/store_client_sessions.go @@ -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. diff --git a/internal/logic/logic.go b/internal/logic/logic.go index f92c84a..10c24ee 100644 --- a/internal/logic/logic.go +++ b/internal/logic/logic.go @@ -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" diff --git a/internal/logic/statistic/statistic.go b/internal/logic/statistic/statistic.go new file mode 100644 index 0000000..40dce37 --- /dev/null +++ b/internal/logic/statistic/statistic.go @@ -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 +} diff --git a/internal/model/do/store_client_sessions.go b/internal/model/do/store_client_sessions.go new file mode 100644 index 0000000..c364372 --- /dev/null +++ b/internal/model/do/store_client_sessions.go @@ -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 +} diff --git a/internal/model/do/store_netfee_area_level.go b/internal/model/do/store_netfee_area_level.go index 4301bfb..da3e91a 100644 --- a/internal/model/do/store_netfee_area_level.go +++ b/internal/model/do/store_netfee_area_level.go @@ -11,16 +11,14 @@ import ( // StoreNetfeeAreaLevel is the golang structure of table store_netfee_area_level for DAO operations like Where/Data. type StoreNetfeeAreaLevel struct { - g.Meta `orm:"table:store_netfee_area_level, do:true"` - Id interface{} // 主键ID - StoreId interface{} // 门店ID - RewardId interface{} // 奖励ID(rewards表主键) - AreaId interface{} // 区域ID(外部系统) - AreaName interface{} // 区域名称 - MemberLevelId interface{} // 会员等级ID(外部系统) - MemberLevelName interface{} // 会员等级名称 - PriceData interface{} // 7x24价格矩阵 - CreatedAt *gtime.Time // 创建时间 - UpdatedAt *gtime.Time // 更新时间 - DeletedAt *gtime.Time // 删除时间 + g.Meta `orm:"table:store_netfee_area_level, do:true"` + Id interface{} // 主键ID + StoreId interface{} // 门店ID + RewardId interface{} // 奖励ID(rewards表主键) + AreaId interface{} // 区域ID(外部系统) + MemberLevelId interface{} // 会员等级ID(外部系统) + PriceData interface{} // 7x24价格矩阵 + CreatedAt *gtime.Time // 创建时间 + UpdatedAt *gtime.Time // 更新时间 + DeletedAt *gtime.Time // 删除时间 } diff --git a/internal/model/entity/store_client_sessions.go b/internal/model/entity/store_client_sessions.go new file mode 100644 index 0000000..7356036 --- /dev/null +++ b/internal/model/entity/store_client_sessions.go @@ -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 +} diff --git a/internal/model/entity/store_netfee_area_level.go b/internal/model/entity/store_netfee_area_level.go index fbb4db0..b82a6b1 100644 --- a/internal/model/entity/store_netfee_area_level.go +++ b/internal/model/entity/store_netfee_area_level.go @@ -10,15 +10,13 @@ import ( // StoreNetfeeAreaLevel is the golang structure for table store_netfee_area_level. type StoreNetfeeAreaLevel struct { - Id int64 `json:"id" orm:"id" description:"主键ID"` // 主键ID - StoreId int64 `json:"storeId" orm:"store_id" description:"门店ID"` // 门店ID - RewardId int64 `json:"rewardId" orm:"reward_id" description:"奖励ID(rewards表主键)"` // 奖励ID(rewards表主键) - 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:"更新时间"` // 更新时间 - DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"删除时间"` // 删除时间 + Id int64 `json:"id" orm:"id" description:"主键ID"` // 主键ID + StoreId int64 `json:"storeId" orm:"store_id" description:"门店ID"` // 门店ID + RewardId int64 `json:"rewardId" orm:"reward_id" description:"奖励ID(rewards表主键)"` // 奖励ID(rewards表主键) + AreaId int64 `json:"areaId" orm:"area_id" description:"区域ID(外部系统)"` // 区域ID(外部系统) + MemberLevelId int64 `json:"memberLevelId" orm:"member_level_id" description:"会员等级ID(外部系统)"` // 会员等级ID(外部系统) + 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:"更新时间"` // 更新时间 + DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"删除时间"` // 删除时间 } diff --git a/internal/model/statistic.go b/internal/model/statistic.go new file mode 100644 index 0000000..832818b --- /dev/null +++ b/internal/model/statistic.go @@ -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"` +} diff --git a/internal/service/statistic.go b/internal/service/statistic.go new file mode 100644 index 0000000..3228cbf --- /dev/null +++ b/internal/service/statistic.go @@ -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 +}