|
|
package repository
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
|
|
|
)
|
|
|
|
|
|
type BusinessBonusRepository struct {
|
|
|
transactionContext *transaction.TransactionContext
|
|
|
}
|
|
|
|
|
|
func (repository *BusinessBonusRepository) transformPgModelToDomainModel(BusinessBonusModel *models.BusinessBonus) (domain.BusinessBonus, error) {
|
|
|
m := domain.BusinessBonus{}
|
|
|
return m, nil
|
|
|
}
|
|
|
|
|
|
func NewBusinessBonusRepository(transactionContext *transaction.TransactionContext) (*BusinessBonusRepository, error) {
|
|
|
if transactionContext == nil {
|
|
|
return nil, fmt.Errorf("transactionContext参数不能为nil")
|
|
|
}
|
|
|
return &BusinessBonusRepository{transactionContext: transactionContext}, nil
|
|
|
}
|
|
|
|
|
|
func (repository *BusinessBonusRepository) Add(dm *domain.BusinessBonus) error {
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
bonusModel := models.BusinessBonus{
|
|
|
Id: dm.Id,
|
|
|
CompanyId: dm.CompanyId,
|
|
|
PartnerInfoId: dm.PartnerInfoId,
|
|
|
Bonus: dm.Bonus,
|
|
|
BonusNot: dm.Bonus,
|
|
|
BonusExpense: dm.BonusExpense,
|
|
|
IsDisable: dm.IsDisable,
|
|
|
BonusStatus: dm.BonusStatus,
|
|
|
}
|
|
|
_, err := tx.Model(&bonusModel).
|
|
|
Insert()
|
|
|
dm.CreateAt = bonusModel.CreateAt
|
|
|
dm.UpdateAt = bonusModel.UpdateAt
|
|
|
dm.Id = bonusModel.Id
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func (repository *BusinessBonusRepository) Edit(dm *domain.BusinessBonus) error {
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
bonusModel := models.BusinessBonus{
|
|
|
Id: dm.Id,
|
|
|
CompanyId: dm.CompanyId,
|
|
|
PartnerInfoId: dm.PartnerInfoId,
|
|
|
Bonus: dm.Bonus,
|
|
|
BonusNot: dm.Bonus,
|
|
|
BonusExpense: dm.BonusExpense,
|
|
|
IsDisable: dm.IsDisable,
|
|
|
BonusStatus: dm.BonusStatus,
|
|
|
CreateAt: dm.CreateAt,
|
|
|
UpdateAt: dm.UpdateAt,
|
|
|
}
|
|
|
_, err := tx.Model(&bonusModel).WherePK().Update()
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
func (repository *BusinessBonusRepository) FindOne(queryOptions domain.BusinessBonusFindOneQuery) (*domain.BusinessBonus, error) {
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
BusinessBonusModel := new(models.BusinessBonus)
|
|
|
var hasCondition bool
|
|
|
query := tx.Model(BusinessBonusModel).Where("delete_at ISNULL")
|
|
|
if queryOptions.Id > 0 {
|
|
|
hasCondition = true
|
|
|
query = query.Where("id=?", queryOptions.Id)
|
|
|
}
|
|
|
if queryOptions.PartnerId > 0 {
|
|
|
hasCondition = true
|
|
|
query = query.Where("partner_info_id=?", queryOptions.PartnerId)
|
|
|
}
|
|
|
if !hasCondition {
|
|
|
return nil, errors.New("没有查询条件")
|
|
|
}
|
|
|
if err := query.First(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
data, err := repository.transformPgModelToDomainModel(BusinessBonusModel)
|
|
|
return &data, err
|
|
|
}
|
|
|
|
|
|
func (repository *BusinessBonusRepository) Find(queryOptions domain.BusinessBonusFindQuery) (int, []domain.BusinessBonus, error) {
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
var (
|
|
|
err error
|
|
|
cnt int
|
|
|
businessBonuss []domain.BusinessBonus
|
|
|
businessBonusModels []models.BusinessBonus
|
|
|
)
|
|
|
query := tx.Model(&businessBonusModels)
|
|
|
if cnt, err = query.SelectAndCount(); err != nil {
|
|
|
return 0, businessBonuss, err
|
|
|
}
|
|
|
for i := range businessBonusModels {
|
|
|
if businessBonus, err := repository.transformPgModelToDomainModel(&businessBonusModels[i]); err != nil {
|
|
|
return 0, businessBonuss, err
|
|
|
} else {
|
|
|
businessBonuss = append(businessBonuss, businessBonus)
|
|
|
}
|
|
|
}
|
|
|
return cnt, businessBonuss, nil
|
|
|
} |
...
|
...
|
|