|
|
package repository
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"time"
|
|
|
|
...
|
...
|
@@ -111,10 +110,7 @@ func (reponsitory UsersRepository) Edit(u *domain.Users) error { |
|
|
return err
|
|
|
}
|
|
|
|
|
|
func (reponsitory UsersRepository) FindOne(queryOptions map[string]interface{}) (domain.Users, error) {
|
|
|
if len(queryOptions) == 0 {
|
|
|
return domain.Users{}, errors.New("queryOptions is empty")
|
|
|
}
|
|
|
func (reponsitory UsersRepository) FindOne(queryOptions domain.UsersFindOneQuery) (domain.Users, error) {
|
|
|
var (
|
|
|
err error
|
|
|
tx = reponsitory.transactionContext.PgTx
|
...
|
...
|
@@ -122,17 +118,17 @@ func (reponsitory UsersRepository) FindOne(queryOptions map[string]interface{}) |
|
|
)
|
|
|
query := tx.Model(&m)
|
|
|
query.Where("deleted_at ISNULL")
|
|
|
if v, ok := queryOptions["Id"]; ok {
|
|
|
query = query.Where("id=?", v)
|
|
|
if queryOptions.Id > 0 {
|
|
|
query = query.Where("id=?", queryOptions.Id)
|
|
|
}
|
|
|
if v, ok := queryOptions["Phone"]; ok {
|
|
|
query = query.Where("phone=?", v)
|
|
|
if len(queryOptions.Phone) > 0 {
|
|
|
query = query.Where("phone=?", queryOptions.Phone)
|
|
|
}
|
|
|
if v, ok := queryOptions["CompanyId"]; ok {
|
|
|
query = query.Where("company_id=?", v)
|
|
|
if queryOptions.CompanyId > 0 {
|
|
|
query = query.Where("company_id=?", queryOptions.CompanyId)
|
|
|
}
|
|
|
if v, ok := queryOptions["OpenId"]; ok {
|
|
|
query = query.Where("open_id=?", v)
|
|
|
if queryOptions.OpenId > 0 {
|
|
|
query = query.Where("open_id=?", queryOptions.OpenId)
|
|
|
}
|
|
|
err = query.First()
|
|
|
if err != nil {
|
...
|
...
|
@@ -141,31 +137,27 @@ func (reponsitory UsersRepository) FindOne(queryOptions map[string]interface{}) |
|
|
return reponsitory.transformPgModelToDomainModel(&m)
|
|
|
}
|
|
|
|
|
|
func (reponsitory UsersRepository) Find(queryOption map[string]interface{}) (int, []domain.Users, error) {
|
|
|
func (reponsitory UsersRepository) Find(queryOption domain.UsersFindQuery) (int, []domain.Users, error) {
|
|
|
db := reponsitory.transactionContext.PgTx
|
|
|
usersModels := []models.Users{}
|
|
|
query := db.Model(&usersModels)
|
|
|
query.Where("deleted_at ISNULL")
|
|
|
if v, ok := queryOption["CompanyId"]; ok {
|
|
|
query = query.Where("company_id=?", v)
|
|
|
if queryOption.CompanyId > 0 {
|
|
|
query = query.Where("company_id=?", queryOption.CompanyId)
|
|
|
}
|
|
|
if v, ok := queryOption["ChargeStatus"]; ok {
|
|
|
query = query.Where("charge_status=?", v)
|
|
|
if queryOption.ChargeStatus > 0 {
|
|
|
query = query.Where("charge_status=?", queryOption.ChargeStatus)
|
|
|
}
|
|
|
if v, ok := queryOption["AdminType"]; ok {
|
|
|
query = query.Where("admin_type=?", v)
|
|
|
if queryOption.AdminType > 0 {
|
|
|
query = query.Where("admin_type=?", queryOption.AdminType)
|
|
|
}
|
|
|
if v, ok := queryOption["Offset"]; ok {
|
|
|
offset := v.(int)
|
|
|
query = query.Offset(offset)
|
|
|
if queryOption.Offset >= 0 {
|
|
|
query = query.Offset(queryOption.Offset)
|
|
|
}
|
|
|
if v, ok := queryOption["Limit"]; ok {
|
|
|
limit := v.(int)
|
|
|
if limit > 0 {
|
|
|
query = query.Limit(limit)
|
|
|
}
|
|
|
if queryOption.Limit > 0 {
|
|
|
query = query.Limit(queryOption.Limit)
|
|
|
} else {
|
|
|
query = query.Limit(20)
|
|
|
query = query.Limit(1000)
|
|
|
}
|
|
|
var (
|
|
|
err error
|
...
|
...
|
|