...
|
...
|
@@ -7,14 +7,14 @@ import ( |
|
|
. "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
|
|
|
)
|
|
|
|
|
|
type CustomerServiceRepository struct {
|
|
|
type ImCustomerServiceRepository struct {
|
|
|
transactionContext *transaction.TransactionContext
|
|
|
}
|
|
|
|
|
|
func (repository *CustomerServiceRepository) Save(dm *domain.CustomerService) (*domain.CustomerService, error) {
|
|
|
func (repository *ImCustomerServiceRepository) Save(dm *domain.ImCustomerService) (*domain.ImCustomerService, error) {
|
|
|
var (
|
|
|
err error
|
|
|
m = &models.CustomerService{}
|
|
|
m = &models.ImCustomerService{}
|
|
|
tx = repository.transactionContext.PgTx
|
|
|
)
|
|
|
if err = GobModelTransform(m, dm); err != nil {
|
...
|
...
|
@@ -32,63 +32,63 @@ func (repository *CustomerServiceRepository) Save(dm *domain.CustomerService) (* |
|
|
return dm, nil
|
|
|
}
|
|
|
|
|
|
func (repository *CustomerServiceRepository) Remove(CustomerService *domain.CustomerService) (*domain.CustomerService, error) {
|
|
|
func (repository *ImCustomerServiceRepository) Remove(ImCustomerService *domain.ImCustomerService) (*domain.ImCustomerService, error) {
|
|
|
var (
|
|
|
tx = repository.transactionContext.PgTx
|
|
|
CustomerServiceModel = &models.CustomerService{Id: CustomerService.Identify().(int64)}
|
|
|
ImCustomerServiceModel = &models.ImCustomerService{Id: ImCustomerService.Identify().(int64)}
|
|
|
)
|
|
|
if _, err := tx.Model(CustomerServiceModel).Where("id = ?", CustomerService.Id).Delete(); err != nil {
|
|
|
return CustomerService, err
|
|
|
if _, err := tx.Model(ImCustomerServiceModel).Where("id = ?", ImCustomerService.Id).Delete(); err != nil {
|
|
|
return ImCustomerService, err
|
|
|
}
|
|
|
return CustomerService, nil
|
|
|
return ImCustomerService, nil
|
|
|
}
|
|
|
|
|
|
func (repository *CustomerServiceRepository) FindOne(queryOptions map[string]interface{}) (*domain.CustomerService, error) {
|
|
|
func (repository *ImCustomerServiceRepository) FindOne(queryOptions map[string]interface{}) (*domain.ImCustomerService, error) {
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
CustomerServiceModel := new(models.CustomerService)
|
|
|
query := NewQuery(tx.Model(CustomerServiceModel), queryOptions)
|
|
|
ImCustomerServiceModel := new(models.ImCustomerService)
|
|
|
query := NewQuery(tx.Model(ImCustomerServiceModel), queryOptions)
|
|
|
query.SetWhere("id = ?", "id")
|
|
|
query.SetWhere("user_id = ?", "user_id")
|
|
|
if err := query.First(); err != nil {
|
|
|
return nil, domain.QueryNoRow
|
|
|
}
|
|
|
if CustomerServiceModel.Id == 0 {
|
|
|
if ImCustomerServiceModel.Id == 0 {
|
|
|
return nil, domain.QueryNoRow
|
|
|
}
|
|
|
return repository.transformPgModelToDomainModel(CustomerServiceModel)
|
|
|
return repository.transformPgModelToDomainModel(ImCustomerServiceModel)
|
|
|
}
|
|
|
|
|
|
func (repository *CustomerServiceRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CustomerService, error) {
|
|
|
func (repository *ImCustomerServiceRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ImCustomerService, error) {
|
|
|
tx := repository.transactionContext.PgTx
|
|
|
var CustomerServiceModels []*models.CustomerService
|
|
|
CustomerServices := make([]*domain.CustomerService, 0)
|
|
|
query := NewQuery(tx.Model(&CustomerServiceModels), queryOptions).
|
|
|
var ImCustomerServiceModels []*models.ImCustomerService
|
|
|
ImCustomerServices := make([]*domain.ImCustomerService, 0)
|
|
|
query := NewQuery(tx.Model(&ImCustomerServiceModels), queryOptions).
|
|
|
SetOrder("create_time", "sortByCreateTime").
|
|
|
SetOrder("update_time", "sortByUpdateTime").
|
|
|
SetOrder("id", "sortById")
|
|
|
var err error
|
|
|
if query.AffectRow, err = query.SelectAndCount(); err != nil {
|
|
|
return 0, CustomerServices, err
|
|
|
return 0, ImCustomerServices, err
|
|
|
}
|
|
|
for _, CustomerServiceModel := range CustomerServiceModels {
|
|
|
if CustomerService, err := repository.transformPgModelToDomainModel(CustomerServiceModel); err != nil {
|
|
|
return 0, CustomerServices, err
|
|
|
for _, ImCustomerServiceModel := range ImCustomerServiceModels {
|
|
|
if ImCustomerService, err := repository.transformPgModelToDomainModel(ImCustomerServiceModel); err != nil {
|
|
|
return 0, ImCustomerServices, err
|
|
|
} else {
|
|
|
CustomerServices = append(CustomerServices, CustomerService)
|
|
|
ImCustomerServices = append(ImCustomerServices, ImCustomerService)
|
|
|
}
|
|
|
}
|
|
|
return int64(query.AffectRow), CustomerServices, nil
|
|
|
return int64(query.AffectRow), ImCustomerServices, nil
|
|
|
}
|
|
|
|
|
|
func (repository *CustomerServiceRepository) transformPgModelToDomainModel(CustomerServiceModel *models.CustomerService) (*domain.CustomerService, error) {
|
|
|
m := &domain.CustomerService{}
|
|
|
err := GobModelTransform(m, CustomerServiceModel)
|
|
|
func (repository *ImCustomerServiceRepository) transformPgModelToDomainModel(ImCustomerServiceModel *models.ImCustomerService) (*domain.ImCustomerService, error) {
|
|
|
m := &domain.ImCustomerService{}
|
|
|
err := GobModelTransform(m, ImCustomerServiceModel)
|
|
|
return m, err
|
|
|
}
|
|
|
|
|
|
func NewCustomerServiceRepository(transactionContext *transaction.TransactionContext) (*CustomerServiceRepository, error) {
|
|
|
func NewImCustomerServiceRepository(transactionContext *transaction.TransactionContext) (*ImCustomerServiceRepository, error) {
|
|
|
if transactionContext == nil {
|
|
|
return nil, ERR_EMPTY_TC
|
|
|
}
|
|
|
return &CustomerServiceRepository{transactionContext: transactionContext}, nil
|
|
|
return &ImCustomerServiceRepository{transactionContext: transactionContext}, nil
|
|
|
} |
...
|
...
|
|