-
Notifications
You must be signed in to change notification settings - Fork 0
/
gfApplication.go
107 lines (89 loc) · 2.99 KB
/
gfApplication.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package gfApplication
import (
"encoding/json"
"fmt"
"github.com/dkzhang/RmsGo/myUtils/timeParse"
"github.com/dkzhang/RmsGo/webapi/model/resource"
"time"
)
type AppNewProRes struct {
ProjectName string `json:"project_name"`
resource.Resource
StartDateStr string `json:"start_date"`
StartDate time.Time `json:"-"`
TotalDaysApply int `json:"total_days_apply"`
EndDateStr string `json:"end_date"`
EndDate time.Time `json:"-"`
}
// 将时间从0点统一调整至特定时刻
const TimeAdjust = time.Hour * 10
func JsonUnmarshalAppNewProRes(jsonStr string) (appn AppNewProRes, err error) {
err = json.Unmarshal([]byte(jsonStr), &appn)
if err != nil {
return AppNewProRes{}, fmt.Errorf("json.Unmarshal error: %v", err)
}
appn.StartDate, err = timeParse.ParseDateShangHai(appn.StartDateStr)
if err != nil {
return AppNewProRes{}, fmt.Errorf("timeParse StartDate error: %v", err)
}
appn.EndDate, err = timeParse.ParseDateShangHai(appn.EndDateStr)
if err != nil {
return AppNewProRes{}, fmt.Errorf("timeParse EndDate error: %v", err)
}
if appn.TotalDaysApply != int(appn.EndDate.Sub(appn.StartDate).Hours()/24) {
return AppNewProRes{},
fmt.Errorf("TotalDaysApply compution error, start=%v, end=%v, duration=%d days",
appn.StartDate, appn.EndDate, appn.TotalDaysApply)
}
// 将时间从0点统一调整至特定时刻
appn.StartDate = appn.StartDate.Add(TimeAdjust)
appn.EndDate = appn.EndDate.Add(TimeAdjust)
return appn, nil
}
type AppResChange struct {
resource.Resource
DaysExtended int `json:"days_extended"`
EndDateStr string `json:"end_date"`
EndDate time.Time `json:"-"`
}
func JsonUnmarshalAppResChange(jsonStr string) (appc AppResChange, err error) {
err = json.Unmarshal([]byte(jsonStr), &appc)
if err != nil {
return AppResChange{}, fmt.Errorf("json.Unmarshal error: %v", err)
}
appc.EndDate, err = timeParse.ParseDateShangHai(appc.EndDateStr)
if err != nil {
return AppResChange{}, fmt.Errorf("timeParse EndDate error: %v", err)
}
// 将时间从0点统一调整至特定时刻
appc.EndDate = appc.EndDate.Add(TimeAdjust)
return appc, nil
}
type AppResComReturn struct {
CGpuType int `json:"cgpu_type"` // cpu=1, gpu=2
NodesAfterReturn []int64 `json:"nodes_after_return"`
}
func JsonUnmarshalAppResComReturn(jsonStr string) (arcr AppResComReturn, err error) {
err = json.Unmarshal([]byte(jsonStr), &arcr)
if err != nil {
return AppResComReturn{}, fmt.Errorf("json.Unmarshal error: %v", err)
}
return arcr, nil
}
type AppResStoReturn struct {
SizeAfter int `json:"size_after"`
}
func JsonUnmarshalAppResStoReturn(jsonStr string) (arsr AppResStoReturn, err error) {
err = json.Unmarshal([]byte(jsonStr), &arsr)
if err != nil {
return AppResStoReturn{}, fmt.Errorf("json.Unmarshal error: %v", err)
}
return arsr, nil
}
type CtrlApprovalInfoWithProjectCode struct {
ProjectCode string `json:"project_code"`
Comment string `json:"comment"`
}
type ApprovalInfo struct {
Comment string `json:"comment"`
}