103 lines
3.1 KiB
Go
103 lines
3.1 KiB
Go
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
|
|
|
package instances
|
|
|
|
import (
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
|
"github.com/TeaOSLab/EdgeUser/internal/utils/dateutils"
|
|
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
|
"github.com/iwind/TeaGo/maps"
|
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
|
)
|
|
|
|
type IndexAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *IndexAction) Init() {
|
|
this.Nav("", "", "")
|
|
}
|
|
|
|
func (this *IndexAction) RunGet(params struct {
|
|
NetworkId int64
|
|
PeriodId int64
|
|
}) {
|
|
countResp, err := this.RPC().UserADInstanceRPC().CountUserADInstances(this.UserContext(), &pb.CountUserADInstancesRequest{
|
|
AdNetworkId: params.NetworkId,
|
|
ExpiresDay: "",
|
|
AdPackagePeriodId: params.PeriodId,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
var count = countResp.Count
|
|
var page = this.NewPage(count)
|
|
this.Data["page"] = page.AsHTML()
|
|
|
|
userInstancesResp, err := this.RPC().UserADInstanceRPC().ListUserADInstances(this.UserContext(), &pb.ListUserADInstancesRequest{
|
|
AdNetworkId: params.NetworkId,
|
|
AdPackagePeriodId: params.PeriodId,
|
|
ExpiresDay: "",
|
|
AvailableOnly: false,
|
|
Offset: page.Offset,
|
|
Size: page.Size,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
|
|
var userInstanceMaps = []maps.Map{}
|
|
for _, userInstance := range userInstancesResp.UserADInstances {
|
|
// 实例
|
|
var instanceMap = maps.Map{
|
|
"id": 0,
|
|
"userInstanceId": 0,
|
|
}
|
|
if userInstance.AdPackageInstance != nil {
|
|
instanceMap = maps.Map{
|
|
"id": userInstance.AdPackageInstance.Id,
|
|
"userInstanceId": userInstance.AdPackageInstance.UserInstanceId,
|
|
}
|
|
}
|
|
|
|
// 产品
|
|
var packageMap = maps.Map{
|
|
"id": 0,
|
|
}
|
|
if userInstance.AdPackageInstance != nil && userInstance.AdPackageInstance.AdPackage != nil {
|
|
packageMap = maps.Map{
|
|
"id": userInstance.AdPackageInstance.AdPackage.Id,
|
|
"summary": userInstance.AdPackageInstance.AdPackage.Summary,
|
|
}
|
|
}
|
|
|
|
// 实例
|
|
var ipAddresses = []string{}
|
|
if userInstance.AdPackageInstance != nil && len(userInstance.AdPackageInstance.IpAddresses) > 0 {
|
|
ipAddresses = userInstance.AdPackageInstance.IpAddresses
|
|
}
|
|
|
|
userInstanceMaps = append(userInstanceMaps, maps.Map{
|
|
"id": userInstance.Id,
|
|
"dayFrom": dateutils.SplitYmd(userInstance.DayFrom),
|
|
"dayTo": dateutils.SplitYmd(userInstance.DayTo),
|
|
"instance": instanceMap,
|
|
"package": packageMap,
|
|
"ipAddresses": ipAddresses,
|
|
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", userInstance.CreatedAt),
|
|
"periodCount": userInstance.AdPackagePeriodCount,
|
|
"periodUnitName": userconfigs.ADPackagePeriodUnitName(userInstance.AdPackagePeriodUnit),
|
|
"canDelete": true,
|
|
"isExpired": userInstance.DayTo < timeutil.Format("Ymd"),
|
|
"isAvailable": userInstance.IsAvailable,
|
|
"countObjects": userInstance.CountObjects,
|
|
})
|
|
}
|
|
this.Data["userInstances"] = userInstanceMaps
|
|
|
|
this.Show()
|
|
}
|