pg_common_statistics_service.go
4.4 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
package domain_service
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"time"
)
// PgCommonStatisticsService 通用统计服务
type PgCommonStatisticsService struct {
transactionContext *pgTransaction.TransactionContext
}
const (
// 共创产品统计数据
CooperationGoodsStatistics = iota + 1
)
var (
MapKey = map[int]string{
CooperationGoodsStatistics: "cooperationGoodsStatistics",
}
)
// Scan 扫描需要统计的项
//
// keyFlags 统计项标识符号
// queryOption 查询参数
func (ptr *PgCommonStatisticsService) Scan(keyFlags []int, queryOption map[string]interface{}) (interface{}, error) {
var res = make(map[string]interface{})
for i := range keyFlags {
switch keyFlags[i] {
case CooperationGoodsStatistics:
}
}
return res, nil
}
// totalOrganizationUser 统计组织用户
// rankType 排行榜类型,1月榜,2年榜 3总榜,默认展示年榜
// top 排名前n个
func (ptr *PgCommonStatisticsService) CooperationGoodsStatistics(companyId, orgId int64, rankType int, top int) ([]*domain.CooperationGoodsStatisticsDto, error) {
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
queryOptions := make(map[string]interface{})
queryOptions["companyId"] = companyId
queryOptions["orgId"] = orgId
y := time.Now().Year()
m := time.Now().Month()
var beginTime, endTime time.Time
if rankType == 1 { //1月榜
beginTime = time.Date(y, m, 1, 0, 0, 0, 0, time.Local)
endTime = beginTime.AddDate(0, 1, 0)
queryOptions["beginTime"] = beginTime
queryOptions["endTime"] = endTime
} else if rankType == 2 { //2年榜
beginTime = time.Date(y, 1, 1, 0, 0, 0, 0, time.Local)
endTime = beginTime.AddDate(1, 0, 0)
queryOptions["beginTime"] = beginTime
queryOptions["endTime"] = endTime
}
if top >0{
queryOptions["limit"] = top
}
goods,err:= orderGoodDao.CooperationGoodsStatistics(queryOptions)
if err!=nil{
return nil,err
}
// 2.计算百分比
var totalAmount float64
for i:=range goods{
goods[i].Rank = int32(i)
totalAmount +=goods[i].GoodAmount
}
for i:=range goods{
goods[i].GoodRatio = utils.Round((goods[i].GoodAmount / totalAmount)*100,0)
}
return goods,nil
}
// CooperationModeStatistics 企业-共创模式统计
//
// p1 p1_desc
func (ptr *PgCommonStatisticsService) CooperationModeStatistics(companyId, orgId int64) ([]*domain.CooperationModeStatisticsDto, error){
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
queryOptions := make(map[string]interface{})
queryOptions["companyId"] = companyId
queryOptions["orgId"] = orgId
modeStatistics,err:= orderGoodDao.CooperationModeStatistics(queryOptions)
if err!=nil{
return nil,err
}
return modeStatistics, nil
}
// DividendsStatistics 分红统计
//
// action 1:当前月
func (ptr *PgCommonStatisticsService) DividendsStatistics(companyId, orgId int64,action int) (interface{}, error){
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
queryOptions := make(map[string]interface{})
queryOptions["companyId"] = companyId
queryOptions["orgId"] = orgId
var beginTime, endTime time.Time
var res = make(map[string]interface{})
if action==1{
y := time.Now().Year()
m := time.Now().Month()
beginTime = time.Date(y, m, 1, 0, 0, 0, 0, time.Local)
endTime = beginTime.AddDate(0, 1, 0)
queryOptions["beginTime"] = beginTime
queryOptions["endTime"] = endTime
}
totalDividends,err:= orderGoodDao.DividendsStatistics(queryOptions)
if err!=nil{
return nil,err
}
res["creditAccount"] = totalDividends.DividendsEstimate
res["orderAmount"] = totalDividends.OrderAmount
queryOptions["paymentStatus"] = 2
dividendsEstimate,err:= orderGoodDao.DividendsStatistics(queryOptions)
if err!=nil{
return nil,err
}
res["dividendsEstimate"] = dividendsEstimate.DividendsEstimate
return res, nil
}
func (ptr *PgCommonStatisticsService) loadQueryOptions(queryOption map[string]interface{}, keys ...string) (map[string]interface{}, error) {
var res = make(map[string]interface{})
for i := 0; i < len(keys); i++ {
k := keys[i]
if v, ok := queryOption[k]; ok {
res[k] = v
} else {
return nil, fmt.Errorf("参数 %v 不存在", k)
}
}
return res, nil
}
type item struct {
key string
val interface{}
}