作者 陈志颖

feat:仓储查询方法增加查询所有

... ... @@ -36,7 +36,6 @@ type CooperationModeRepository interface {
BatchRemove(cooperationModes []*CooperationMode) ([]*CooperationMode, error)
FindOne(queryOptions map[string]interface{}) (*CooperationMode, error)
Find(queryOptions map[string]interface{}) (int64, []*CooperationMode, error)
FindAll(queryOptions map[string]interface{}) (int64, []*CooperationMode, error)
}
func (cooperationMode *CooperationMode) Identify() interface{} {
... ...
... ... @@ -159,13 +159,19 @@ func (repository *ContractUndertakerFeedbackRepository) Find(queryOptions map[st
// 搜索内容包括项目合约名称、承接人姓名、承接内容关键字
if matchWord, ok := queryOptions["matchWord"]; ok && matchWord != "" {
query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
q.WhereOr("cooperation_contract_name like ?",fmt.Sprintf("%%%s%%", matchWord))
q.WhereOr("cooperation_contract_name like ?", fmt.Sprintf("%%%s%%", matchWord))
q.WhereOr("contract_undertaker->>'userName' like ?", fmt.Sprintf("%%%s%%", matchWord))
q.WhereOr("feedback_content like ?", fmt.Sprintf("%%%s%%", matchWord))
return q, nil
})
}
query.SetOffsetAndLimit(20)
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("feedback_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, contractUndertakerFeedbacks, err
... ...
... ... @@ -196,7 +196,13 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
if cooperationApplicationStatus, ok := queryOptions["cooperationApplicationStatus"]; ok && cooperationApplicationStatus.(int32) != 0 {
}
query.SetOffsetAndLimit(20)
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("cooperation_application_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationApplications, err
... ...
... ... @@ -141,7 +141,13 @@ func (repository *CooperationContractChangeLogRepository) Find(queryOptions map[
var cooperationContractChangeLogModels []*models.CooperationContractChangeLog
cooperationContractChangeLogs := make([]*domain.CooperationContractChangeLog, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractChangeLogModels), queryOptions)
query.SetOffsetAndLimit(20)
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("cooperation_contract_change_log_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationContractChangeLogs, err
... ...
... ... @@ -166,7 +166,13 @@ func (repository *CooperationContractRelevantRepository) Find(queryOptions map[s
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevants := make([]*domain.CooperationContractRelevant, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractRelevantModels), queryOptions)
query.SetOffsetAndLimit(20)
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("cooperation_contract_relevant_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationContractRelevants, err
... ...
... ... @@ -594,7 +594,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
func (repository *CooperationContractRepository) UpdateMany(cooperationContracts []*domain.CooperationContract) ([]*domain.CooperationContract, error) {
tx := repository.transactionContext.PgTx
var cooperationContractModels []*models.CooperationContract
cooperationContractQuery := tx.Model(&cooperationContractModels)
for _, cooperationContract := range cooperationContracts {
cooperationContractModels = append(cooperationContractModels, &models.CooperationContract{
CooperationContractId: cooperationContract.CooperationContractId,
... ... @@ -615,7 +614,7 @@ func (repository *CooperationContractRepository) UpdateMany(cooperationContracts
UpdatedAt: time.Now(),
})
}
if _, err := tx.Model(&cooperationContractQuery).WherePK().Update(); err != nil {
if _, err := tx.Model(&cooperationContractModels).WherePK().Update(); err != nil {
return nil, err
}
return cooperationContracts, nil
... ... @@ -739,7 +738,13 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
if sponsorName, ok := queryOptions["sponsorName"]; ok && sponsorName != "" {
query.Where(`(cooperation_contract.cooperation_contract_sponsor->>'userName')::text LIKE ?`, fmt.Sprintf("%%%s%%", sponsorName))
}
query.SetOffsetAndLimit(20)
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("cooperation_contract_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationContracts, err
... ...
... ... @@ -181,7 +181,13 @@ func (repository *CooperationContractUndertakerRepository) Find(queryOptions map
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakers := make([]*domain.CooperationContractUndertaker, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractUndertakerModels), queryOptions)
query.SetOffsetAndLimit(20)
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("cooperation_contract_undertaker_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationContractUndertakers, err
... ...
... ... @@ -175,32 +175,12 @@ func (repository *CooperationModeRepository) Find(queryOptions map[string]interf
if organizationName, ok := queryOptions["organizationName"]; ok && organizationName != "" {
query.Where("org->>'orgName' like ?", fmt.Sprintf("%%%s%%", organizationName))
}
query.SetOffsetAndLimit(20)
query.SetOrderDirect("cooperation_mode_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationModes, err
} else {
for _, cooperationModeModel := range cooperationModeModels {
if cooperationMode, err := transform.TransformToCooperationModeDomainModelFromPgModels(cooperationModeModel); err != nil {
return 0, cooperationModes, err
} else {
cooperationModes = append(cooperationModes, cooperationMode)
}
}
return int64(count), cooperationModes, nil
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
}
func (repository *CooperationModeRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.CooperationMode, error) {
tx := repository.transactionContext.PgTx
var cooperationModeModels []*models.CooperationMode
cooperationModes := make([]*domain.CooperationMode, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationModeModels), queryOptions)
if cooperationModeName, ok := queryOptions["cooperationModeName"]; ok && cooperationModeName != "" {
query.Where("cooperation_mode_name like ?", fmt.Sprintf("%%%s%%", cooperationModeName))
}
if organizationName, ok := queryOptions["organizationName"]; ok && organizationName != "" {
query.Where("org->>'orgName' like ?", fmt.Sprintf("%%%s%%", organizationName))
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("cooperation_mode_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
... ...
... ... @@ -202,7 +202,13 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int
if v, ok := queryOptions["status"]; ok && v.(int32) > 0 {
query.Where("status =? ", v)
}
query.SetOffsetAndLimit(20)
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("cooperation_project_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationProjects, err
... ...
... ... @@ -176,7 +176,13 @@ func (repository *CreditAccountRepository) Find(queryOptions map[string]interfac
var creditAccountModels []*models.CreditAccount
creditAccounts := make([]*domain.CreditAccount, 0)
query := sqlbuilder.BuildQuery(tx.Model(&creditAccountModels), queryOptions)
query.SetOffsetAndLimit(20)
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("credit_account_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, creditAccounts, err
... ...
... ... @@ -176,7 +176,13 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
var dividendsEstimateModels []*models.DividendsEstimate
dividendsEstimates := make([]*domain.DividendsEstimate, 0)
query := sqlbuilder.BuildQuery(tx.Model(&dividendsEstimateModels), queryOptions)
query.SetOffsetAndLimit(20)
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("dividends_estimate_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, dividendsEstimates, err
... ...
... ... @@ -161,7 +161,13 @@ func (repository *DividendsIncentivesRuleRepository) Find(queryOptions map[strin
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRules := make([]*domain.DividendsIncentivesRule, 0)
query := sqlbuilder.BuildQuery(tx.Model(&dividendsIncentivesRuleModels), queryOptions)
query.SetOffsetAndLimit(20)
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("dividends_incentives_rule_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, dividendsIncentivesRules, err
... ...
... ... @@ -299,7 +299,13 @@ func (repository *DividendsOrderRepository) Find(queryOptions map[string]interfa
var dividendsOrderModels []*models.DividendsOrder
dividendsOrders := make([]*domain.DividendsOrder, 0)
query := sqlbuilder.BuildQuery(tx.Model(&dividendsOrderModels), queryOptions)
query.SetOffsetAndLimit(20)
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("dividends_order_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, dividendsOrders, err
... ...
... ... @@ -306,7 +306,13 @@ func (repository *DividendsReturnedOrderRepository) Find(queryOptions map[string
var dividendsReturnedOrderModels []*models.DividendsReturnedOrder
dividendsReturnedOrders := make([]*domain.DividendsReturnedOrder, 0)
query := sqlbuilder.BuildQuery(tx.Model(&dividendsReturnedOrderModels), queryOptions)
query.SetOffsetAndLimit(20)
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("dividends_returned_order_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, dividendsReturnedOrders, err
... ...
... ... @@ -161,7 +161,13 @@ func (repository *MoneyIncentivesRuleRepository) Find(queryOptions map[string]in
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRules := make([]*domain.MoneyIncentivesRule, 0)
query := sqlbuilder.BuildQuery(tx.Model(&moneyIncentivesRuleModels), queryOptions)
query.SetOffsetAndLimit(20)
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("money_incentives_rule_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, moneyIncentivesRules, err
... ...
... ... @@ -156,7 +156,13 @@ func (repository *OrderGoodRepository) Find(queryOptions map[string]interface{})
var orderGoodModels []*models.OrderGood
orderGoods := make([]*domain.OrderGood, 0)
query := sqlbuilder.BuildQuery(tx.Model(&orderGoodModels), queryOptions)
query.SetOffsetAndLimit(20)
offsetLimitFlag := true
if limit, ok := queryOptions["limit"]; ok {
offsetLimitFlag = limit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("order_good_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, orderGoods, err
... ...