1
|
package domain_service
|
1
|
package domain_service
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
|
|
4
|
+ "encoding/json"
|
4
|
"fmt"
|
5
|
"fmt"
|
5
|
"github.com/go-pg/pg/v10"
|
6
|
"github.com/go-pg/pg/v10"
|
6
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
7
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
@@ -13,6 +14,13 @@ const ( |
|
@@ -13,6 +14,13 @@ const ( |
13
|
SearchContractDividends = "SearchContractDividends"
|
14
|
SearchContractDividends = "SearchContractDividends"
|
14
|
// 获取分红合约详情
|
15
|
// 获取分红合约详情
|
15
|
GetContractDividends = "GetContractDividends"
|
16
|
GetContractDividends = "GetContractDividends"
|
|
|
17
|
+
|
|
|
18
|
+ // 企业-商品统计
|
|
|
19
|
+ CooperationGoodsStatistics = "cooperationGoodsStatistics"
|
|
|
20
|
+ // 企业-共创模式统计
|
|
|
21
|
+ CooperationModeStatistics = "CooperationModeStatistics"
|
|
|
22
|
+ // 企业-分红统计
|
|
|
23
|
+ CompanyDividendsStatistics = "CompanyDividendsStatistics"
|
16
|
)
|
24
|
)
|
17
|
|
25
|
|
18
|
// CooperationStatisticsService 共创统计服务
|
26
|
// CooperationStatisticsService 共创统计服务
|
|
@@ -20,6 +28,16 @@ type CooperationStatisticsService struct { |
|
@@ -20,6 +28,16 @@ type CooperationStatisticsService struct { |
20
|
transactionContext *pgTransaction.TransactionContext
|
28
|
transactionContext *pgTransaction.TransactionContext
|
21
|
}
|
29
|
}
|
22
|
|
30
|
|
|
|
31
|
+func NewCooperationStatisticsService(transactionContext *pgTransaction.TransactionContext) (*CooperationStatisticsService, error) {
|
|
|
32
|
+ if transactionContext == nil {
|
|
|
33
|
+ return nil, fmt.Errorf("transactionContext参数不能为nil")
|
|
|
34
|
+ } else {
|
|
|
35
|
+ return &CooperationStatisticsService{
|
|
|
36
|
+ transactionContext: transactionContext,
|
|
|
37
|
+ }, nil
|
|
|
38
|
+ }
|
|
|
39
|
+}
|
|
|
40
|
+
|
23
|
/***** 1.合约分红模块 *****/
|
41
|
/***** 1.合约分红模块 *****/
|
24
|
|
42
|
|
25
|
/*1.1 分红合约搜索*/
|
43
|
/*1.1 分红合约搜索*/
|
|
@@ -34,14 +52,15 @@ type CooperationStatisticsService struct { |
|
@@ -34,14 +52,15 @@ type CooperationStatisticsService struct { |
34
|
// - orgId
|
52
|
// - orgId
|
35
|
// 按个人
|
53
|
// 按个人
|
36
|
// - userBaseId
|
54
|
// - userBaseId
|
37
|
-func (svr *CooperationStatisticsService) SearchContractDividends(queryOptions map[string]interface{}) (interface{}, error) {
|
55
|
+func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions map[string]interface{}) (interface{}, error) {
|
38
|
// 1.根据个人、企业查询合约列表
|
56
|
// 1.根据个人、企业查询合约列表
|
39
|
var contracts []*domain.CooperationContract
|
57
|
var contracts []*domain.CooperationContract
|
40
|
var err error
|
58
|
var err error
|
41
|
if _, ok := queryOptions["userBaseId"]; ok {
|
59
|
if _, ok := queryOptions["userBaseId"]; ok {
|
42
|
- contracts, err = svr.getUserContracts(queryOptions)
|
|
|
43
|
- } else if _, ok := queryOptions["orgId"]; ok {
|
|
|
44
|
- contracts, err = svr.getCompanyContracts(queryOptions)
|
60
|
+ contracts, err = ptr.getUserContracts(queryOptions)
|
|
|
61
|
+ } else if v, ok := queryOptions["orgId"]; ok {
|
|
|
62
|
+ queryOptions["orgId"], _ = (v.(json.Number)).Int64()
|
|
|
63
|
+ contracts, err = ptr.getCompanyContracts(queryOptions)
|
45
|
}
|
64
|
}
|
46
|
if err != nil {
|
65
|
if err != nil {
|
47
|
return nil, err
|
66
|
return nil, err
|
|
@@ -62,7 +81,7 @@ func (svr *CooperationStatisticsService) SearchContractDividends(queryOptions ma |
|
@@ -62,7 +81,7 @@ func (svr *CooperationStatisticsService) SearchContractDividends(queryOptions ma |
62
|
results = append(results, resultItem)
|
81
|
results = append(results, resultItem)
|
63
|
numbers = append(numbers, item.CooperationContractNumber)
|
82
|
numbers = append(numbers, item.CooperationContractNumber)
|
64
|
}
|
83
|
}
|
65
|
- mapEstimate, err := svr.getContractsDividendsEstimate(numbers)
|
84
|
+ mapEstimate, err := ptr.getContractsDividendsEstimate(numbers)
|
66
|
if err != nil {
|
85
|
if err != nil {
|
67
|
return nil, err
|
86
|
return nil, err
|
68
|
}
|
87
|
}
|
|
@@ -79,8 +98,8 @@ func (svr *CooperationStatisticsService) SearchContractDividends(queryOptions ma |
|
@@ -79,8 +98,8 @@ func (svr *CooperationStatisticsService) SearchContractDividends(queryOptions ma |
79
|
// getUserContracts 获取用户的合约列表
|
98
|
// getUserContracts 获取用户的合约列表
|
80
|
//
|
99
|
//
|
81
|
// p1 p1_desc
|
100
|
// p1 p1_desc
|
82
|
-func (svr *CooperationStatisticsService) getUserContracts(queryOptions map[string]interface{}) ([]*domain.CooperationContract, error) {
|
|
|
83
|
- undertakerRepository, _ := repository.NewCooperationContractUndertakerRepository(svr.transactionContext)
|
101
|
+func (ptr *CooperationStatisticsService) getUserContracts(queryOptions map[string]interface{}) ([]*domain.CooperationContract, error) {
|
|
|
102
|
+ undertakerRepository, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext)
|
84
|
_, undertakers, err := undertakerRepository.Find(queryOptions)
|
103
|
_, undertakers, err := undertakerRepository.Find(queryOptions)
|
85
|
var numbers []string
|
104
|
var numbers []string
|
86
|
for i := range undertakers {
|
105
|
for i := range undertakers {
|
|
@@ -90,7 +109,7 @@ func (svr *CooperationStatisticsService) getUserContracts(queryOptions map[strin |
|
@@ -90,7 +109,7 @@ func (svr *CooperationStatisticsService) getUserContracts(queryOptions map[strin |
90
|
return []*domain.CooperationContract{}, nil
|
109
|
return []*domain.CooperationContract{}, nil
|
91
|
}
|
110
|
}
|
92
|
queryOptions["inCooperationContractNumber"] = numbers
|
111
|
queryOptions["inCooperationContractNumber"] = numbers
|
93
|
- contractRepository, _ := repository.NewCooperationContractRepository(svr.transactionContext)
|
112
|
+ contractRepository, _ := repository.NewCooperationContractRepository(ptr.transactionContext)
|
94
|
// TODO: 参数查询条件
|
113
|
// TODO: 参数查询条件
|
95
|
_, contracts, err := contractRepository.Find(queryOptions)
|
114
|
_, contracts, err := contractRepository.Find(queryOptions)
|
96
|
return contracts, err
|
115
|
return contracts, err
|
|
@@ -99,21 +118,21 @@ func (svr *CooperationStatisticsService) getUserContracts(queryOptions map[strin |
|
@@ -99,21 +118,21 @@ func (svr *CooperationStatisticsService) getUserContracts(queryOptions map[strin |
99
|
// getCompanyContracts 获取组织合约列表
|
118
|
// getCompanyContracts 获取组织合约列表
|
100
|
//
|
119
|
//
|
101
|
// p1 p1_desc
|
120
|
// p1 p1_desc
|
102
|
-func (svr *CooperationStatisticsService) getCompanyContracts(queryOptions map[string]interface{}) ([]*domain.CooperationContract, error) {
|
|
|
103
|
- contractRepository, _ := repository.NewCooperationContractRepository(svr.transactionContext)
|
121
|
+func (ptr *CooperationStatisticsService) getCompanyContracts(queryOptions map[string]interface{}) ([]*domain.CooperationContract, error) {
|
|
|
122
|
+ contractRepository, _ := repository.NewCooperationContractRepository(ptr.transactionContext)
|
104
|
// TODO: 参数查询条件
|
123
|
// TODO: 参数查询条件
|
105
|
_, contracts, err := contractRepository.Find(queryOptions)
|
124
|
_, contracts, err := contractRepository.Find(queryOptions)
|
106
|
return contracts, err
|
125
|
return contracts, err
|
107
|
}
|
126
|
}
|
108
|
|
127
|
|
109
|
// getContractsDividendsEstimate 合约分红预算
|
128
|
// getContractsDividendsEstimate 合约分红预算
|
110
|
-func (svr *CooperationStatisticsService) getContractsDividendsEstimate(numbers []string) (map[string]*domain.DividendsEstimate, error) {
|
129
|
+func (ptr *CooperationStatisticsService) getContractsDividendsEstimate(numbers []string) (map[string]*domain.DividendsEstimate, error) {
|
111
|
var estimates []*domain.DividendsEstimate
|
130
|
var estimates []*domain.DividendsEstimate
|
112
|
var resMap = make(map[string]*domain.DividendsEstimate)
|
131
|
var resMap = make(map[string]*domain.DividendsEstimate)
|
113
|
if len(numbers) == 0 {
|
132
|
if len(numbers) == 0 {
|
114
|
return resMap, nil
|
133
|
return resMap, nil
|
115
|
}
|
134
|
}
|
116
|
- _, err := svr.transactionContext.PgDd.Query(&estimates, `select cooperation_contract_number,sum(dividends_amount) dividends_amount from dividends_estimates
|
135
|
+ _, err := ptr.transactionContext.PgDd.Query(&estimates, `select cooperation_contract_number,sum(dividends_amount) dividends_amount from dividends_estimates
|
117
|
where cooperation_contract_number in (?)
|
136
|
where cooperation_contract_number in (?)
|
118
|
group by cooperation_contract_number
|
137
|
group by cooperation_contract_number
|
119
|
`, pg.In(numbers))
|
138
|
`, pg.In(numbers))
|
|
@@ -144,16 +163,6 @@ type searchContractDividendsResult struct { |
|
@@ -144,16 +163,6 @@ type searchContractDividendsResult struct { |
144
|
CreatedAt int64 `json:"createdAt"`
|
163
|
CreatedAt int64 `json:"createdAt"`
|
145
|
}
|
164
|
}
|
146
|
|
165
|
|
147
|
-func NewCooperationStatisticsService(transactionContext *pgTransaction.TransactionContext) (*CooperationStatisticsService, error) {
|
|
|
148
|
- if transactionContext == nil {
|
|
|
149
|
- return nil, fmt.Errorf("transactionContext参数不能为nil")
|
|
|
150
|
- } else {
|
|
|
151
|
- return &CooperationStatisticsService{
|
|
|
152
|
- transactionContext: transactionContext,
|
|
|
153
|
- }, nil
|
|
|
154
|
- }
|
|
|
155
|
-}
|
|
|
156
|
-
|
|
|
157
|
/*1.2 分红合约详情*/
|
166
|
/*1.2 分红合约详情*/
|
158
|
|
167
|
|
159
|
// 分红合约搜索
|
168
|
// 分红合约搜索
|
|
@@ -164,9 +173,9 @@ func NewCooperationStatisticsService(transactionContext *pgTransaction.Transacti |
|
@@ -164,9 +173,9 @@ func NewCooperationStatisticsService(transactionContext *pgTransaction.Transacti |
164
|
// - orgId
|
173
|
// - orgId
|
165
|
// 按个人
|
174
|
// 按个人
|
166
|
// - userBaseId
|
175
|
// - userBaseId
|
167
|
-func (svr *CooperationStatisticsService) GetContractDividends(queryOptions map[string]interface{}) (interface{}, error) {
|
176
|
+func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[string]interface{}) (interface{}, error) {
|
168
|
// 1.合约详情
|
177
|
// 1.合约详情
|
169
|
- contractRepository, _ := repository.NewCooperationContractRepository(svr.transactionContext)
|
178
|
+ contractRepository, _ := repository.NewCooperationContractRepository(ptr.transactionContext)
|
170
|
if _, ok := queryOptions["contractId"]; !ok {
|
179
|
if _, ok := queryOptions["contractId"]; !ok {
|
171
|
return nil, fmt.Errorf("合约ID(contractId)不能为空")
|
180
|
return nil, fmt.Errorf("合约ID(contractId)不能为空")
|
172
|
}
|
181
|
}
|