|
|
package domain_service
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/go-pg/pg/v10"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
...
|
...
|
@@ -13,6 +14,13 @@ const ( |
|
|
SearchContractDividends = "SearchContractDividends"
|
|
|
// 获取分红合约详情
|
|
|
GetContractDividends = "GetContractDividends"
|
|
|
|
|
|
// 企业-商品统计
|
|
|
CooperationGoodsStatistics = "cooperationGoodsStatistics"
|
|
|
// 企业-共创模式统计
|
|
|
CooperationModeStatistics = "CooperationModeStatistics"
|
|
|
// 企业-分红统计
|
|
|
CompanyDividendsStatistics = "CompanyDividendsStatistics"
|
|
|
)
|
|
|
|
|
|
// CooperationStatisticsService 共创统计服务
|
...
|
...
|
@@ -20,6 +28,16 @@ type CooperationStatisticsService struct { |
|
|
transactionContext *pgTransaction.TransactionContext
|
|
|
}
|
|
|
|
|
|
func NewCooperationStatisticsService(transactionContext *pgTransaction.TransactionContext) (*CooperationStatisticsService, error) {
|
|
|
if transactionContext == nil {
|
|
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|
|
|
} else {
|
|
|
return &CooperationStatisticsService{
|
|
|
transactionContext: transactionContext,
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/***** 1.合约分红模块 *****/
|
|
|
|
|
|
/*1.1 分红合约搜索*/
|
...
|
...
|
@@ -34,14 +52,15 @@ type CooperationStatisticsService struct { |
|
|
// - orgId
|
|
|
// 按个人
|
|
|
// - userBaseId
|
|
|
func (svr *CooperationStatisticsService) SearchContractDividends(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
// 1.根据个人、企业查询合约列表
|
|
|
var contracts []*domain.CooperationContract
|
|
|
var err error
|
|
|
if _, ok := queryOptions["userBaseId"]; ok {
|
|
|
contracts, err = svr.getUserContracts(queryOptions)
|
|
|
} else if _, ok := queryOptions["orgId"]; ok {
|
|
|
contracts, err = svr.getCompanyContracts(queryOptions)
|
|
|
contracts, err = ptr.getUserContracts(queryOptions)
|
|
|
} else if v, ok := queryOptions["orgId"]; ok {
|
|
|
queryOptions["orgId"], _ = (v.(json.Number)).Int64()
|
|
|
contracts, err = ptr.getCompanyContracts(queryOptions)
|
|
|
}
|
|
|
if err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -62,7 +81,7 @@ func (svr *CooperationStatisticsService) SearchContractDividends(queryOptions ma |
|
|
results = append(results, resultItem)
|
|
|
numbers = append(numbers, item.CooperationContractNumber)
|
|
|
}
|
|
|
mapEstimate, err := svr.getContractsDividendsEstimate(numbers)
|
|
|
mapEstimate, err := ptr.getContractsDividendsEstimate(numbers)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
...
|
...
|
@@ -79,8 +98,8 @@ func (svr *CooperationStatisticsService) SearchContractDividends(queryOptions ma |
|
|
// getUserContracts 获取用户的合约列表
|
|
|
//
|
|
|
// p1 p1_desc
|
|
|
func (svr *CooperationStatisticsService) getUserContracts(queryOptions map[string]interface{}) ([]*domain.CooperationContract, error) {
|
|
|
undertakerRepository, _ := repository.NewCooperationContractUndertakerRepository(svr.transactionContext)
|
|
|
func (ptr *CooperationStatisticsService) getUserContracts(queryOptions map[string]interface{}) ([]*domain.CooperationContract, error) {
|
|
|
undertakerRepository, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext)
|
|
|
_, undertakers, err := undertakerRepository.Find(queryOptions)
|
|
|
var numbers []string
|
|
|
for i := range undertakers {
|
...
|
...
|
@@ -90,7 +109,7 @@ func (svr *CooperationStatisticsService) getUserContracts(queryOptions map[strin |
|
|
return []*domain.CooperationContract{}, nil
|
|
|
}
|
|
|
queryOptions["inCooperationContractNumber"] = numbers
|
|
|
contractRepository, _ := repository.NewCooperationContractRepository(svr.transactionContext)
|
|
|
contractRepository, _ := repository.NewCooperationContractRepository(ptr.transactionContext)
|
|
|
// TODO: 参数查询条件
|
|
|
_, contracts, err := contractRepository.Find(queryOptions)
|
|
|
return contracts, err
|
...
|
...
|
@@ -99,21 +118,21 @@ func (svr *CooperationStatisticsService) getUserContracts(queryOptions map[strin |
|
|
// getCompanyContracts 获取组织合约列表
|
|
|
//
|
|
|
// p1 p1_desc
|
|
|
func (svr *CooperationStatisticsService) getCompanyContracts(queryOptions map[string]interface{}) ([]*domain.CooperationContract, error) {
|
|
|
contractRepository, _ := repository.NewCooperationContractRepository(svr.transactionContext)
|
|
|
func (ptr *CooperationStatisticsService) getCompanyContracts(queryOptions map[string]interface{}) ([]*domain.CooperationContract, error) {
|
|
|
contractRepository, _ := repository.NewCooperationContractRepository(ptr.transactionContext)
|
|
|
// TODO: 参数查询条件
|
|
|
_, contracts, err := contractRepository.Find(queryOptions)
|
|
|
return contracts, err
|
|
|
}
|
|
|
|
|
|
// getContractsDividendsEstimate 合约分红预算
|
|
|
func (svr *CooperationStatisticsService) getContractsDividendsEstimate(numbers []string) (map[string]*domain.DividendsEstimate, error) {
|
|
|
func (ptr *CooperationStatisticsService) getContractsDividendsEstimate(numbers []string) (map[string]*domain.DividendsEstimate, error) {
|
|
|
var estimates []*domain.DividendsEstimate
|
|
|
var resMap = make(map[string]*domain.DividendsEstimate)
|
|
|
if len(numbers) == 0 {
|
|
|
return resMap, nil
|
|
|
}
|
|
|
_, err := svr.transactionContext.PgDd.Query(&estimates, `select cooperation_contract_number,sum(dividends_amount) dividends_amount from dividends_estimates
|
|
|
_, err := ptr.transactionContext.PgDd.Query(&estimates, `select cooperation_contract_number,sum(dividends_amount) dividends_amount from dividends_estimates
|
|
|
where cooperation_contract_number in (?)
|
|
|
group by cooperation_contract_number
|
|
|
`, pg.In(numbers))
|
...
|
...
|
@@ -144,16 +163,6 @@ type searchContractDividendsResult struct { |
|
|
CreatedAt int64 `json:"createdAt"`
|
|
|
}
|
|
|
|
|
|
func NewCooperationStatisticsService(transactionContext *pgTransaction.TransactionContext) (*CooperationStatisticsService, error) {
|
|
|
if transactionContext == nil {
|
|
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|
|
|
} else {
|
|
|
return &CooperationStatisticsService{
|
|
|
transactionContext: transactionContext,
|
|
|
}, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/*1.2 分红合约详情*/
|
|
|
|
|
|
// 分红合约搜索
|
...
|
...
|
@@ -164,9 +173,9 @@ func NewCooperationStatisticsService(transactionContext *pgTransaction.Transacti |
|
|
// - orgId
|
|
|
// 按个人
|
|
|
// - userBaseId
|
|
|
func (svr *CooperationStatisticsService) GetContractDividends(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
// 1.合约详情
|
|
|
contractRepository, _ := repository.NewCooperationContractRepository(svr.transactionContext)
|
|
|
contractRepository, _ := repository.NewCooperationContractRepository(ptr.transactionContext)
|
|
|
if _, ok := queryOptions["contractId"]; !ok {
|
|
|
return nil, fmt.Errorf("合约ID(contractId)不能为空")
|
|
|
}
|
...
|
...
|
|