statistics_person.go
4.9 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
package service
import (
"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.项目概览统计
contracts, err := gateway.CooperationContractSearch(allied_creation_cooperation.ReqCooperationContractSearch{
PageNumber: 1,
PageSize: 1,
UserBaseId: cmd.Operator.UserBaseId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
stoppedContracts, err := gateway.CooperationContractSearch(allied_creation_cooperation.ReqCooperationContractSearch{
PageNumber: 1,
PageSize: 1,
Status: 2,
UserBaseId: cmd.Operator.UserBaseId,
})
if 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,
UserBaseId: cmd.Operator.UserBaseId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var overview = map[string]interface{}{
"contractSum": contracts.Grid.Total, //总合约数
"contractStoppedSum": stoppedContracts.Grid.Total, //停止的合约数
"companySum": users.Count, //共创企业数
}
// 2.本月分红统计 - 个人
dividendStatisticsResult, err := gateway.CooperationStatistics(allied_creation_cooperation.DividendsStatistics, map[string]interface{}{
"userBaseId": cmd.Operator.UserBaseId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
type AnnualDividend struct {
AnnualDividends struct {
Accounted int `json:"accounted"`
Accounting int `json:"accounting"`
Paid int `json:"paid"`
Total int `json:"total"`
} `json:"annualDividends"`
}
var annualDividend = &AnnualDividend{}
if err := json.UnmarshalFromString(json.MarshalToString(dividendStatisticsResult), annualDividend); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
dividendStatistics := map[string]interface{}{
"dividendAmount": annualDividend.AnnualDividends.Total, // 分红金额
"paidAmount": annualDividend.AnnualDividends.Paid, // 已支付
"unPaidAmount": annualDividend.AnnualDividends.Accounting, // 未支付
}
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,
UserType: domain.UserTypeCooperation,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var values []interface{}
for i := range users.Users {
user := users.Users[i]
item := map[string]interface{}{
"company": user.Company,
"cooperationProjectCount": 0,
"cooperationContractCount": 0,
"dividendsRatio": 0,
"dividendsIncome": 0,
}
values = append(values, item)
}
return map[string]interface{}{
"list": values,
}, nil
}
// CooperationProjectRecommend TODO:其他公司按公开的项目查 猜你喜欢(共创项目)
func (srv PersonStatisticsService) CooperationProjectRecommend(projectQuery *command.ListCooperationProjectQuery) (int64, interface{}, error) {
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
projectQuery.Operator)
result, err := creationCooperationGateway.CooperationProjectsSearch(allied_creation_cooperation.ReqCooperationProjectSearch{
PageNumber: projectQuery.PageNumber,
PageSize: projectQuery.PageSize,
})
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return int64(result.Total), result.List, nil
}