statistics_person.go
14.0 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
package service
import (
"time"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/json"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
// 个人端统计 【0%】
type PersonStatisticsService struct {
}
// IndexStatistics 个人端 - 首页统计 (入口页面统计数据)
func (srv PersonStatisticsService) IndexStatistics(cmd *command.IndexStatisticsCommand) (interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
// 1.项目概览统计
contractStatisticsResult, err := gateway.CooperationStatistics(allied_creation_cooperation.PersonCooperationContractStatistics, map[string]interface{}{
"userBaseId": cmd.Operator.UserBaseId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
type contractStatistics struct {
ContractSum int `json:"contractSum"`
ContractStoppedSum int `json:"contractStoppedSum"`
}
var cs = &contractStatistics{}
if err := json.UnmarshalFromString(json.MarshalToString(contractStatisticsResult), cs); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
gatewayUser := allied_creation_user.NewHttplibAlliedCreationUser(
cmd.Operator)
users, err := gatewayUser.UserSearch(allied_creation_user.ReqUserSearch{
Limit: 1,
Offset: 0,
UserType: domain.UserTypeCooperation | domain.UserTypeEmployee,
UserBaseId: cmd.Operator.UserBaseId,
EnableStatus: domain.UserStatusEnable,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var overview = map[string]interface{}{
"contractSum": cs.ContractSum, //总合约数
"contractStoppedSum": cs.ContractStoppedSum, //停止的合约数
"companySum": users.Count, //共创企业数
}
year, month, _ := time.Now().Date()
beginTime := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
endTime := beginTime.AddDate(0, 1, 0)
// 2.本月分红统计 - 个人
unPaidResult, err := gateway.CooperationStatistics(allied_creation_cooperation.CreditAccountStatistics, map[string]interface{}{
"userBaseId": cmd.Operator.UserBaseId,
"beginTime": beginTime,
"endTime": endTime,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
type AnnualDividend struct {
Total float64 `json:"total"`
Accounting float64 `json:"accounting"`
Accounted float64 `json:"accounted"`
Paid float64 `json:"paid"`
Unpaid float64 `json:"unpaid"`
}
var annualUnPaidDividend = &AnnualDividend{}
if err := json.UnmarshalFromString(json.MarshalToString(unPaidResult), annualUnPaidDividend); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
// 2.本月分红统计 - 个人
paymentResult, err := gateway.CooperationStatistics(allied_creation_cooperation.CreditAccountStatistics, map[string]interface{}{
"userBaseId": cmd.Operator.UserBaseId,
"paymentBeginTime": beginTime,
"paymentEndTime": endTime,
})
var annualPaymentDividend = &AnnualDividend{}
if err := json.UnmarshalFromString(json.MarshalToString(paymentResult), annualPaymentDividend); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
dividendStatistics := map[string]interface{}{
"dividendAmount": annualPaymentDividend.Paid + annualUnPaidDividend.Unpaid, // 分红金额 annualDividend.Total
"paidAmount": annualPaymentDividend.Paid, // 已支付
"unPaidAmount": annualUnPaidDividend.Unpaid, // 未支付
}
return map[string]interface{}{
"overview": overview,
"dividendStatistics": dividendStatistics,
}, nil
}
// IndexStatistics 个人端 - 首页统计 (入口页面统计数据)
func (srv PersonStatisticsService) IndexStatisticsV2(cmd *command.IndexStatisticsCommand) (interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
// 1.项目概览统计
contractStatisticsResult, err := gateway.CooperationStatistics(allied_creation_cooperation.PersonCooperationContractStatistics, map[string]interface{}{
"userBaseId": cmd.Operator.UserBaseId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
type contractStatistics struct {
ContractSum int `json:"contractSum"`
ContractStoppedSum int `json:"contractStoppedSum"`
}
var cs = &contractStatistics{}
if err := json.UnmarshalFromString(json.MarshalToString(contractStatisticsResult), cs); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var response = struct {
OrgIds []int `json:"orgIds"`
}{}
err = gateway.CooperationStatisticsWithObject(allied_creation_cooperation.PersonCooperationCompany, map[string]interface{}{
"userBaseId": cmd.Operator.UserBaseId,
}, &response)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var overview = map[string]interface{}{
"contractSum": cs.ContractSum, //总合约数
"contractStoppedSum": cs.ContractStoppedSum, //停止的合约数
"companySum": len(response.OrgIds), //共创企业数
}
year, month, _ := time.Now().Date()
beginTime := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
endTime := beginTime.AddDate(0, 1, 0)
// 2.本月分红统计 - 个人
unPaidResult, err := gateway.CooperationStatistics(allied_creation_cooperation.CreditAccountStatistics, map[string]interface{}{
"userBaseId": cmd.Operator.UserBaseId,
"beginTime": beginTime,
"endTime": endTime,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
type AnnualDividend struct {
Total float64 `json:"total"`
Accounting float64 `json:"accounting"`
Accounted float64 `json:"accounted"`
Paid float64 `json:"paid"`
Unpaid float64 `json:"unpaid"`
}
var annualUnPaidDividend = &AnnualDividend{}
if err := json.UnmarshalFromString(json.MarshalToString(unPaidResult), annualUnPaidDividend); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
// 2.本月分红统计 - 个人
paymentResult, err := gateway.CooperationStatistics(allied_creation_cooperation.CreditAccountStatistics, map[string]interface{}{
"userBaseId": cmd.Operator.UserBaseId,
"paymentBeginTime": beginTime,
"paymentEndTime": endTime,
})
var annualPaymentDividend = &AnnualDividend{}
if err := json.UnmarshalFromString(json.MarshalToString(paymentResult), annualPaymentDividend); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
dividendStatistics := map[string]interface{}{
"dividendAmount": annualPaymentDividend.Paid + annualUnPaidDividend.Unpaid, // 分红金额 annualDividend.Total
"paidAmount": annualPaymentDividend.Paid, // 已支付
"unPaidAmount": annualUnPaidDividend.Unpaid, // 未支付
}
return map[string]interface{}{
"overview": overview,
"dividendStatistics": dividendStatistics,
}, nil
}
// CompanyStatistics 共创用户-共创企业统计
func (srv PersonStatisticsService) CompanyStatistics(cmd *command.CooperationPersonStatisticsCommand) (interface{}, error) {
gatewayUser := allied_creation_user.NewHttplibAlliedCreationUser(
cmd.Operator)
users, err := gatewayUser.UserSearch(allied_creation_user.ReqUserSearch{
Limit: 100,
Offset: 0,
UserBaseId: cmd.Operator.UserBaseId,
EnableStatus: domain.UserStatusEnable,
//UserType: domain.UserTypeCooperation,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var companyList []int
for i := range users.Users {
user := users.Users[i]
if user.Org == nil || user.Org.OrgId == 0 {
continue
}
companyList = append(companyList, user.Org.OrgId)
}
if len(companyList) == 0 {
return map[string]interface{}{
"list": []struct{}{},
}, nil
}
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
result, err := gateway.CooperationStatistics(allied_creation_cooperation.CooperationCompanyStatistics, map[string]interface{}{
"userBaseId": cmd.Operator.UserBaseId,
"companyList": companyList,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
type cooperationCompanyStatisticsResponse struct {
// 当天统计的企业id
OrgId int64 `json:"orgId"`
// 共创项目数
CooperationProjectCount int64 `json:"cooperationProjectCount"`
// 共创合约数
CooperationContractCount int64 `json:"cooperationContractCount"`
// 分红占比
DividendsRatio float64 `json:"dividendsRatio"`
// 分红支出
DividendsIncome float64 `json:"dividendsIncome"`
// 企业信息
Company domain.Company `json:"company"`
}
var cooperationCompanyStatisticsResponses []cooperationCompanyStatisticsResponse
if err := json.UnmarshalFromString(json.MarshalToString(result), &cooperationCompanyStatisticsResponses); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
//if len(cooperationCompanyStatisticsResponses) != len(users.Users) {
// return nil, application.ThrowError(application.BUSINESS_ERROR, "数据不匹配")
//}
var values = make([]interface{}, 0)
for i := range users.Users {
user := users.Users[i]
if user.Company == nil {
continue
}
for j := range cooperationCompanyStatisticsResponses {
if user.Org != nil && cooperationCompanyStatisticsResponses[j].OrgId == int64(user.Org.OrgId) {
cooperationCompanyStatisticsResponses[j].Company = domain.Company{
CompanyID: user.Org.OrgId,
CompanyName: user.Org.OrgName,
Logo: user.Company.Logo,
}
values = append(values, cooperationCompanyStatisticsResponses[j])
}
}
}
return map[string]interface{}{
"list": values,
}, nil
}
// CompanyStatistics 共创用户-共创企业统计
func (srv PersonStatisticsService) CompanyStatisticsV2(cmd *command.CooperationPersonStatisticsCommand) (interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
var response = struct {
OrgIds []int `json:"orgIds"`
}{}
err := gateway.CooperationStatisticsWithObject(allied_creation_cooperation.PersonCooperationCompany, map[string]interface{}{
"userBaseId": cmd.Operator.UserBaseId,
}, &response)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var companyList []int = response.OrgIds
if len(companyList) == 0 {
return map[string]interface{}{
"list": []struct{}{},
}, nil
}
result, err := gateway.CooperationStatistics(allied_creation_cooperation.CooperationCompanyStatistics, map[string]interface{}{
"userBaseId": cmd.Operator.UserBaseId,
"companyList": companyList,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
type cooperationCompanyStatisticsResponse struct {
// 当天统计的企业id
OrgId int64 `json:"orgId"`
// 共创项目数
CooperationProjectCount int64 `json:"cooperationProjectCount"`
// 共创合约数
CooperationContractCount int64 `json:"cooperationContractCount"`
// 分红占比
DividendsRatio float64 `json:"dividendsRatio"`
// 分红支出
DividendsIncome float64 `json:"dividendsIncome"`
// 企业信息
Company domain.Company `json:"company"`
}
var cooperationCompanyStatisticsResponses []cooperationCompanyStatisticsResponse
if err := json.UnmarshalFromString(json.MarshalToString(result), &cooperationCompanyStatisticsResponses); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var values = make([]interface{}, 0)
gatewayUser := allied_creation_user.NewHttplibAlliedCreationUser(
cmd.Operator)
for i := range companyList {
for j := range cooperationCompanyStatisticsResponses {
if cooperationCompanyStatisticsResponses[j].OrgId == int64(companyList[i]) {
orgData, err := gatewayUser.OrgGet(allied_creation_user.ReqOrgGet{
OrgId: companyList[i],
FetchFlag: 1,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var companyLog string
if orgData.Company != nil {
companyLog = orgData.Company.Logo
}
cooperationCompanyStatisticsResponses[j].Company = domain.Company{
CompanyID: orgData.OrgID,
CompanyName: orgData.OrgName,
Logo: companyLog,
}
values = append(values, cooperationCompanyStatisticsResponses[j])
}
}
}
return map[string]interface{}{
"list": values,
}, nil
}
// CooperationProjectRecommend TODO:其他公司按公开的项目查 猜你喜欢(共创项目)
func (srv PersonStatisticsService) CooperationProjectRecommend(projectQuery *command.ListCooperationProjectQuery) (int64, interface{}, error) {
if projectQuery.Operator.UserBaseId > 0 {
}
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
projectQuery.Operator)
result, err := creationCooperationGateway.CooperationProjectsSearch(allied_creation_cooperation.ReqCooperationProjectSearch{
PageNumber: projectQuery.PageNumber + 1,
PageSize: projectQuery.PageSize,
CooperationProjectUndertakerType: 3,
//Status: 1,
IsSkipFetchProjectModel: true,
// Status: 1,
SortByStatus: 1,
})
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return int64(result.Total), result.List, nil
}