...
|
...
|
@@ -2,8 +2,12 @@ package dao |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/go-pg/pg/v10"
|
|
|
"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"
|
|
|
"time"
|
|
|
)
|
...
|
...
|
@@ -146,6 +150,76 @@ func (dao *CooperationContractDao) SearchCooperationContractByUndertaker(queryOp |
|
|
}
|
|
|
}
|
|
|
|
|
|
func (dao *CooperationContractDao) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContract, error) {
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
var cooperationContractModels []*models.CooperationContract
|
|
|
cooperationContracts := make([]*domain.CooperationContract, 0)
|
|
|
query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractModels), queryOptions)
|
|
|
if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
|
|
|
query.Where("cooperation_contract_number ilike ?", fmt.Sprintf("%%%s%%", cooperationContractNumber))
|
|
|
}
|
|
|
if cooperationContractName, ok := queryOptions["cooperationContactName"]; ok && cooperationContractName != "" {
|
|
|
query.Where("cooperation_contract_name like ?", fmt.Sprintf("%%%s%%", cooperationContractName))
|
|
|
}
|
|
|
if departmentName, ok := queryOptions["departmentName"]; ok && departmentName != "" {
|
|
|
query.Where(`(cooperation_contract.department->>'departmentName')::test LIKE ?`, fmt.Sprintf("%%%s%%", departmentName))
|
|
|
}
|
|
|
if sponsorName, ok := queryOptions["sponsorName"]; ok && sponsorName != "" {
|
|
|
query.Where(`(cooperation_contract.cooperation_contract_sponsor->>'userName')::text LIKE ?`, fmt.Sprintf("%%%s%%", sponsorName))
|
|
|
}
|
|
|
if cooperationContractIds, ok := queryOptions["cooperationContractIds"]; ok && len(cooperationContractIds.([]int64)) != 0 {
|
|
|
query.Where("cooperation_contract_id in (?)", pg.In(cooperationContractIds))
|
|
|
}
|
|
|
if cooperationContractNumbers, ok := queryOptions["cooperationContractNumbers"]; ok && len(cooperationContractNumbers.([]string)) != 0 {
|
|
|
query.Where("cooperation_contract_number in (?)", pg.In(cooperationContractNumbers))
|
|
|
}
|
|
|
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 incentivesType, ok := queryOptions["incentivesType"]; ok && incentivesType.(int32) != 0 {
|
|
|
query.Where("incentives_type = ?", incentivesType)
|
|
|
}
|
|
|
offsetLimitFlag := true
|
|
|
if offsetLimit, ok := queryOptions["offsetLimit"]; ok {
|
|
|
offsetLimitFlag = offsetLimit.(bool)
|
|
|
}
|
|
|
if offsetLimitFlag {
|
|
|
query.SetOffsetAndLimit(20)
|
|
|
}
|
|
|
query.SetOrderDirect("cooperation_contract_id", "DESC")
|
|
|
var count int
|
|
|
var err error
|
|
|
if count, err = query.SelectAndCount(); err != nil {
|
|
|
return 0, cooperationContracts, err
|
|
|
}
|
|
|
for _, cooperationContractModel := range cooperationContractModels {
|
|
|
// 获取分红激励规则列表
|
|
|
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
|
|
|
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
|
|
|
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
|
|
|
var cooperationContractRelevantModels []*models.CooperationContractRelevant
|
|
|
if cooperationContract, err := transform.TransformToCooperationContractDomainModelFromPgModels(
|
|
|
cooperationContractModel,
|
|
|
&models.CooperationMode{},
|
|
|
dividendsIncentivesRuleModels,
|
|
|
moneyIncentivesRuleModels,
|
|
|
cooperationContractRelevantModels,
|
|
|
cooperationContractUndertakerModels); err != nil {
|
|
|
return 0, cooperationContracts, err
|
|
|
} else {
|
|
|
cooperationContracts = append(cooperationContracts, cooperationContract)
|
|
|
}
|
|
|
}
|
|
|
return int64(count), cooperationContracts, nil
|
|
|
}
|
|
|
|
|
|
func NewCooperationContractDao(transactionContext *pgTransaction.TransactionContext) (*CooperationContractDao, error) {
|
|
|
if transactionContext == nil {
|
|
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|
...
|
...
|
|