作者 yangfu

个人的合约数修改

package dao
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
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/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
)
type CooperationContractUndertakerDao struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *CooperationContractUndertakerDao) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContractUndertaker, error) {
tx := repository.transactionContext.PgTx
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakers := make([]*domain.CooperationContractUndertaker, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractUndertakerModels), queryOptions)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query.Where("org->>'orgId' = '?'", orgId)
}
if orgIds, ok := queryOptions["orgIds"]; ok && len(orgIds.([]int64)) > 0 {
newOrgIds := utils.SliceItoa(orgIds.([]int64))
query.Where("org->>'orgId' in (?)", pg.In(newOrgIds))
}
if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
query.WhereGroup(func(query *orm.Query) (*orm.Query, error) {
query.WhereOr("user_base_id = ? ", userBaseId)
query.WhereOr("referrer->>'userBaseId' = '?' ", userBaseId)
query.WhereOr("salesman->>'userBaseId' = '?' ", userBaseId)
return query, nil
})
}
offsetLimitFlag := true
if offsetLimit, ok := queryOptions["offsetLimit"]; ok {
offsetLimitFlag = offsetLimit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("cooperation_contract_undertaker_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationContractUndertakers, err
} else {
for _, cooperationContractUndertakerModel := range cooperationContractUndertakerModels {
if cooperationContractUndertaker, err := transform.TransformToCooperationContractUndertakerDomainModelFromPgModels(cooperationContractUndertakerModel); err != nil {
return 0, cooperationContractUndertakers, err
} else {
cooperationContractUndertakers = append(cooperationContractUndertakers, cooperationContractUndertaker)
}
}
return int64(count), cooperationContractUndertakers, nil
}
}
func NewCooperationContractUndertakerDao(transactionContext *pgTransaction.TransactionContext) (*CooperationContractUndertakerDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CooperationContractUndertakerDao{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -51,7 +51,7 @@ func (ptr *CooperationStatisticsService) cooperationCompanyStatistics(userBaseId
}
// 2.相关合约统计
cooperationContractRelevantRepository, _ := repository.NewCooperationContractRelevantRepository(ptr.transactionContext)
cooperationContractRelevantRepository, _ := dao.NewCooperationContractUndertakerDao(ptr.transactionContext)
cooperationContractCount, _, err := cooperationContractRelevantRepository.Find(map[string]interface{}{"userBaseId": userBaseId, "orgId": orgId,
"limit": 1})
if err != nil {
... ... @@ -98,8 +98,8 @@ func (ptr *CooperationStatisticsService) PersonCooperationContractStatistics(que
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
cooperationContractUndertaker, _ := repository.NewCooperationContractRelevantRepository(ptr.transactionContext)
queryOptions["limit"] = 10000 //TODO:合约数大于10000时?
cooperationContractUndertaker, _ := dao.NewCooperationContractUndertakerDao(ptr.transactionContext)
_, contractUndertakers, err := cooperationContractUndertaker.Find(queryOptions)
if err != nil {
return nil, nil
... ...