-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis_count.go
187 lines (174 loc) · 6.28 KB
/
analysis_count.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package TMSTransport
import (
CoreSQL "github.com/fotomxq/weeekj_core/v5/core/sql"
CoreSQLAnalysis "github.com/fotomxq/weeekj_core/v5/core/sql/analysis"
CoreSQLTime "github.com/fotomxq/weeekj_core/v5/core/sql/time"
Router2SystemConfig "github.com/fotomxq/weeekj_core/v5/router2/system_config"
)
// ArgsGetAnalysisCount 获取配送单总量
type ArgsGetAnalysisCount struct {
//组织ID
OrgID int64 `db:"org_id" json:"orgID" check:"id"`
//时间范围
// 部分统计支持
TimeBetween CoreSQLTime.DataCoreTime `json:"timeBetween"`
}
func GetAnalysisCount(args *ArgsGetAnalysisCount) (count int64, err error) {
var timeBetween CoreSQLTime.FieldsCoreTime
timeBetween, err = CoreSQLTime.GetBetweenByISO(args.TimeBetween)
if err != nil {
return
}
count, err = CoreSQL.GetAllCountMap(Router2SystemConfig.MainDB.DB, "tms_transport", "id", "org_id = :org_id AND create_at >= :start_at AND create_at <= :end_at AND delete_at < to_timestamp(1000000)", map[string]interface{}{
"org_id": args.OrgID,
"start_at": timeBetween.MinTime,
"end_at": timeBetween.MaxTime,
})
return
}
// ArgsGetAnalysisBindCount 获取配送单总量
type ArgsGetAnalysisBindCount struct {
//组织ID
OrgID int64 `db:"org_id" json:"orgID" check:"id"`
//成员ID
BindID int64 `db:"bind_id" json:"bindID" check:"id"`
//时间范围
// 部分统计支持
TimeBetween CoreSQLTime.DataCoreTime `json:"timeBetween"`
}
func GetAnalysisBindCount(args *ArgsGetAnalysisBindCount) (count int64, err error) {
var timeBetween CoreSQLTime.FieldsCoreTime
timeBetween, err = CoreSQLTime.GetBetweenByISO(args.TimeBetween)
if err != nil {
return
}
count, err = CoreSQL.GetAllCountMap(Router2SystemConfig.MainDB.DB, "tms_transport", "id", "org_id = :org_id AND bind_id = :bind_id AND create_at >= :start_at AND create_at <= :end_at AND delete_at < to_timestamp(1000000)", map[string]interface{}{
"org_id": args.OrgID,
"bind_id": args.BindID,
"start_at": timeBetween.MinTime,
"end_at": timeBetween.MaxTime,
})
return
}
// ArgsGetAnalysisWaitCount 获取配送单未完成总量
type ArgsGetAnalysisWaitCount struct {
//组织ID
OrgID int64 `db:"org_id" json:"orgID" check:"id"`
//时间范围
// 部分统计支持
TimeBetween CoreSQLTime.DataCoreTime `json:"timeBetween"`
}
func GetAnalysisWaitCount(args *ArgsGetAnalysisWaitCount) (count int64, err error) {
var timeBetween CoreSQLTime.FieldsCoreTime
timeBetween, err = CoreSQLTime.GetBetweenByISO(args.TimeBetween)
if err != nil {
return
}
count, err = CoreSQL.GetAllCountMap(Router2SystemConfig.MainDB.DB, "tms_transport", "id", "org_id = :org_id AND create_at >= :start_at AND create_at <= :end_at AND status != 3 AND delete_at < to_timestamp(1000000)", map[string]interface{}{
"org_id": args.OrgID,
"start_at": timeBetween.MinTime,
"end_at": timeBetween.MaxTime,
})
return
}
// ArgsGetAnalysisBindWaitCount 获取配送单未完成总量
type ArgsGetAnalysisBindWaitCount struct {
//组织ID
OrgID int64 `db:"org_id" json:"orgID" check:"id"`
//成员ID
BindID int64 `db:"bind_id" json:"bindID" check:"id"`
//时间范围
// 部分统计支持
TimeBetween CoreSQLTime.DataCoreTime `json:"timeBetween"`
}
func GetAnalysisBindWaitCount(args *ArgsGetAnalysisBindWaitCount) (count int64, err error) {
var timeBetween CoreSQLTime.FieldsCoreTime
timeBetween, err = CoreSQLTime.GetBetweenByISO(args.TimeBetween)
if err != nil {
return
}
count, err = CoreSQL.GetAllCountMap(Router2SystemConfig.MainDB.DB, "tms_transport", "id", "org_id = :org_id AND bind_id = :bind_id AND create_at >= :start_at AND create_at <= :end_at AND status != 3 AND delete_at < to_timestamp(1000000)", map[string]interface{}{
"org_id": args.OrgID,
"bind_id": args.BindID,
"start_at": timeBetween.MinTime,
"end_at": timeBetween.MaxTime,
})
return
}
// GetAnalysisBindFinishCount 获取已完成任务
func GetAnalysisBindFinishCount(args *ArgsGetAnalysisBindWaitCount) (count int64, err error) {
var timeBetween CoreSQLTime.FieldsCoreTime
timeBetween, err = CoreSQLTime.GetBetweenByISO(args.TimeBetween)
if err != nil {
return
}
count, err = CoreSQL.GetAllCountMap(Router2SystemConfig.MainDB.DB, "tms_transport", "id", "org_id = :org_id AND bind_id = :bind_id AND create_at >= :start_at AND create_at <= :end_at AND status = 3 AND delete_at < to_timestamp(1000000)", map[string]interface{}{
"org_id": args.OrgID,
"bind_id": args.BindID,
"start_at": timeBetween.MinTime,
"end_at": timeBetween.MaxTime,
})
return
}
// ArgsGetAnalysisTimeCount 获取配送员分量统计信息参数
type ArgsGetAnalysisTimeCount struct {
//组织ID
OrgID int64 `db:"org_id" json:"orgID" check:"id"`
//查询时间范围
TimeBetween CoreSQLTime.DataCoreTime `json:"timeBetween"`
//结构方式
// year / month / day / hour
TimeType string `json:"timeType"`
}
// DataGetAnalysisTimeCount 获取配送员分量统计信息数据
type DataGetAnalysisTimeCount struct {
//时间
DayTime string `db:"d" json:"dayTime"`
//完成总量
FinishCount int64 `db:"finish_count" json:"finishCount"`
//任务总量
Count int64 `db:"count" json:"count"`
}
// GetAnalysisTimeCount 获取配送员分量统计信息
func GetAnalysisTimeCount(args *ArgsGetAnalysisTimeCount) (dataList []DataGetAnalysisTimeCount, err error) {
var timeBetween CoreSQLTime.FieldsCoreTime
timeBetween, err = CoreSQLTime.GetBetweenByISO(args.TimeBetween)
if err != nil {
return
}
where := "org_id = :org_id"
maps := map[string]interface{}{
"org_id": args.OrgID,
}
where, maps = CoreSQLTime.GetBetweenByTimeAnd("create_at", timeBetween, where, maps)
tableName := "tms_transport"
timeField := CoreSQLAnalysis.GetAnalysisQueryField("create_at", args.TimeType, "d")
err = CoreSQL.GetList(
Router2SystemConfig.MainDB.DB,
&dataList,
"SELECT "+timeField+", COUNT(id) as count FROM "+tableName+" WHERE "+where+" GROUP BY d ORDER BY d",
maps,
)
if err == nil {
var dataList2 []DataGetAnalysisTimeCount
where = where + " AND status = 3"
err = CoreSQL.GetList(
Router2SystemConfig.MainDB.DB,
&dataList2,
"SELECT "+timeField+", COUNT(id) as finish_count FROM "+tableName+" WHERE "+where+" GROUP BY d ORDER BY d",
maps,
)
if err != nil {
return
}
for k, v := range dataList {
for _, v2 := range dataList2 {
if v.DayTime == v2.DayTime {
dataList[k].FinishCount = v2.FinishCount
break
}
}
}
}
return
}