作者 yangfu

个人的合约数修改

  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/go-pg/pg/v10"
  6 + "github.com/go-pg/pg/v10/orm"
  7 + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
  8 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  10 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
  12 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
  13 +)
  14 +
  15 +type CooperationContractUndertakerDao struct {
  16 + transactionContext *pgTransaction.TransactionContext
  17 +}
  18 +
  19 +func (repository *CooperationContractUndertakerDao) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContractUndertaker, error) {
  20 + tx := repository.transactionContext.PgTx
  21 + var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
  22 + cooperationContractUndertakers := make([]*domain.CooperationContractUndertaker, 0)
  23 + query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractUndertakerModels), queryOptions)
  24 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  25 + query.Where("company->>'companyId' = '?'", companyId)
  26 + }
  27 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  28 + query.Where("org->>'orgId' = '?'", orgId)
  29 + }
  30 + if orgIds, ok := queryOptions["orgIds"]; ok && len(orgIds.([]int64)) > 0 {
  31 + newOrgIds := utils.SliceItoa(orgIds.([]int64))
  32 + query.Where("org->>'orgId' in (?)", pg.In(newOrgIds))
  33 + }
  34 + if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
  35 + query.WhereGroup(func(query *orm.Query) (*orm.Query, error) {
  36 + query.WhereOr("user_base_id = ? ", userBaseId)
  37 + query.WhereOr("referrer->>'userBaseId' = '?' ", userBaseId)
  38 + query.WhereOr("salesman->>'userBaseId' = '?' ", userBaseId)
  39 + return query, nil
  40 + })
  41 + }
  42 + offsetLimitFlag := true
  43 + if offsetLimit, ok := queryOptions["offsetLimit"]; ok {
  44 + offsetLimitFlag = offsetLimit.(bool)
  45 + }
  46 + if offsetLimitFlag {
  47 + query.SetOffsetAndLimit(20)
  48 + }
  49 + query.SetOrderDirect("cooperation_contract_undertaker_id", "DESC")
  50 + if count, err := query.SelectAndCount(); err != nil {
  51 + return 0, cooperationContractUndertakers, err
  52 + } else {
  53 + for _, cooperationContractUndertakerModel := range cooperationContractUndertakerModels {
  54 + if cooperationContractUndertaker, err := transform.TransformToCooperationContractUndertakerDomainModelFromPgModels(cooperationContractUndertakerModel); err != nil {
  55 + return 0, cooperationContractUndertakers, err
  56 + } else {
  57 + cooperationContractUndertakers = append(cooperationContractUndertakers, cooperationContractUndertaker)
  58 + }
  59 + }
  60 + return int64(count), cooperationContractUndertakers, nil
  61 + }
  62 +}
  63 +
  64 +func NewCooperationContractUndertakerDao(transactionContext *pgTransaction.TransactionContext) (*CooperationContractUndertakerDao, error) {
  65 + if transactionContext == nil {
  66 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  67 + } else {
  68 + return &CooperationContractUndertakerDao{
  69 + transactionContext: transactionContext,
  70 + }, nil
  71 + }
  72 +}
@@ -51,7 +51,7 @@ func (ptr *CooperationStatisticsService) cooperationCompanyStatistics(userBaseId @@ -51,7 +51,7 @@ func (ptr *CooperationStatisticsService) cooperationCompanyStatistics(userBaseId
51 } 51 }
52 52
53 // 2.相关合约统计 53 // 2.相关合约统计
54 - cooperationContractRelevantRepository, _ := repository.NewCooperationContractRelevantRepository(ptr.transactionContext) 54 + cooperationContractRelevantRepository, _ := dao.NewCooperationContractUndertakerDao(ptr.transactionContext)
55 cooperationContractCount, _, err := cooperationContractRelevantRepository.Find(map[string]interface{}{"userBaseId": userBaseId, "orgId": orgId, 55 cooperationContractCount, _, err := cooperationContractRelevantRepository.Find(map[string]interface{}{"userBaseId": userBaseId, "orgId": orgId,
56 "limit": 1}) 56 "limit": 1})
57 if err != nil { 57 if err != nil {
@@ -98,8 +98,8 @@ func (ptr *CooperationStatisticsService) PersonCooperationContractStatistics(que @@ -98,8 +98,8 @@ func (ptr *CooperationStatisticsService) PersonCooperationContractStatistics(que
98 return nil, err 98 return nil, err
99 } 99 }
100 queryOptions = tool_funs.SimpleStructToMap(&request) 100 queryOptions = tool_funs.SimpleStructToMap(&request)
101 -  
102 - cooperationContractUndertaker, _ := repository.NewCooperationContractRelevantRepository(ptr.transactionContext) 101 + queryOptions["limit"] = 10000 //TODO:合约数大于10000时?
  102 + cooperationContractUndertaker, _ := dao.NewCooperationContractUndertakerDao(ptr.transactionContext)
103 _, contractUndertakers, err := cooperationContractUndertaker.Find(queryOptions) 103 _, contractUndertakers, err := cooperationContractUndertaker.Find(queryOptions)
104 if err != nil { 104 if err != nil {
105 return nil, nil 105 return nil, nil