pg_cooperation_person_statistics_service.go
3.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
package domain_service
import (
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
)
// 共创公司统计
func (ptr *CooperationStatisticsService) CooperationCompanyStatistics(queryOptions map[string]interface{}) (interface{}, error) {
// 参数验证
var request = struct {
UserBaseId int64 `json:"userBaseId" valid:"Required"`
CompanyList []int64 `json:"companyList" valid:"Required"` //公司列表 待统计的公司列表
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
var response = make([]*cooperationCompanyStatisticsResponse, 0)
var totalDividend float64
for i := range request.CompanyList {
orgId := request.CompanyList[i]
item, err := ptr.cooperationCompanyStatistics(request.UserBaseId, orgId)
if err != nil {
return response, err
}
totalDividend += item.DividendsIncome
response = append(response, item)
}
if totalDividend > 0 {
for i := range response {
response[i].DividendsRatio = utils.Round(response[i].DividendsIncome/totalDividend*100, 2)
}
}
return response, nil
}
func (ptr *CooperationStatisticsService) cooperationCompanyStatistics(userBaseId int64, orgId int64) (*cooperationCompanyStatisticsResponse, error) {
// 1.相关项目统计
cooperationApplicationRepository, _ := repository.NewCooperationApplicationRepository(ptr.transactionContext)
cooperationProjectCount, _, err := cooperationApplicationRepository.Find(map[string]interface{}{"userBaseId": userBaseId, "orgId": orgId,
"limit": 1, "cooperationApplicationStatus": int32(2)})
if err != nil {
return nil, err
}
// 2.相关合约统计
cooperationContractRelevantRepository, _ := repository.NewCooperationContractRelevantRepository(ptr.transactionContext)
cooperationContractCount, _, err := cooperationContractRelevantRepository.Find(map[string]interface{}{"userBaseId": userBaseId,
"limit": 1})
if err != nil {
return nil, err
}
// 3.个人分红统计
type response struct {
Total float64 `json:"total"`
Accounting float64 `json:"accounting"`
Accounted float64 `json:"accounted"`
Paid float64 `json:"paid"`
}
creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
var allDividends = &response{}
if err := creditAccountDao.DividendsStatistics(map[string]interface{}{"userBaseId": userBaseId, "orgId": orgId}, allDividends); err != nil {
return nil, err
}
allDividends.Accounting = allDividends.Total - allDividends.Accounted
var ret = &cooperationCompanyStatisticsResponse{
OrgId: orgId,
CooperationProjectCount: cooperationProjectCount,
CooperationContractCount: cooperationContractCount,
DividendsIncome: utils.Round(allDividends.Total, 2),
}
return ret, nil
}
type cooperationCompanyStatisticsResponse struct {
// 当天统计的企业id
OrgId int64 `json:"orgId"`
// 共创项目数
CooperationProjectCount int64 `json:"cooperationProjectCount"`
// 共创合约数
CooperationContractCount int64 `json:"cooperationContractCount"`
// 分红占比
DividendsRatio float64 `json:"dividendsRatio"`
// 分红支出
DividendsIncome float64 `json:"dividendsIncome"`
}