Merge remote-tracking branch 'origin/master'
This commit is contained in:
@ -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"`
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -13,9 +13,10 @@ import (
|
||||
|
||||
// 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.
|
||||
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.
|
||||
@ -57,11 +58,12 @@ var storeClientSessionsColumns = StoreClientSessionsColumns{
|
||||
}
|
||||
|
||||
// NewStoreClientSessionsDao creates and returns a new DAO object for table data access.
|
||||
func NewStoreClientSessionsDao() *StoreClientSessionsDao {
|
||||
func NewStoreClientSessionsDao(handlers ...gdb.ModelHandler) *StoreClientSessionsDao {
|
||||
return &StoreClientSessionsDao{
|
||||
group: "default",
|
||||
table: "store_client_sessions",
|
||||
columns: storeClientSessionsColumns,
|
||||
group: "default",
|
||||
table: "store_client_sessions",
|
||||
columns: storeClientSessionsColumns,
|
||||
handlers: handlers,
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,7 +89,11 @@ func (dao *StoreClientSessionsDao) Group() string {
|
||||
|
||||
// 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 {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
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.
|
||||
|
||||
@ -8,20 +8,15 @@ import (
|
||||
"server/internal/dao/internal"
|
||||
)
|
||||
|
||||
// internalStoreClientSessionsDao is an internal type for wrapping the internal DAO implementation.
|
||||
type internalStoreClientSessionsDao = *internal.StoreClientSessionsDao
|
||||
|
||||
// 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 {
|
||||
internalStoreClientSessionsDao
|
||||
*internal.StoreClientSessionsDao
|
||||
}
|
||||
|
||||
var (
|
||||
// StoreClientSessions is a globally accessible object for table store_client_sessions operations.
|
||||
StoreClientSessions = storeClientSessionsDao{
|
||||
internal.NewStoreClientSessionsDao(),
|
||||
}
|
||||
StoreClientSessions = storeClientSessionsDao{internal.NewStoreClientSessionsDao()}
|
||||
)
|
||||
|
||||
// Add your custom methods and functionality below.
|
||||
|
||||
@ -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"
|
||||
|
||||
47
internal/logic/statistic/statistic.go
Normal file
47
internal/logic/statistic/statistic.go
Normal 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
|
||||
}
|
||||
27
internal/model/statistic.go
Normal file
27
internal/model/statistic.go
Normal 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"`
|
||||
}
|
||||
32
internal/service/statistic.go
Normal file
32
internal/service/statistic.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user