Some checks failed
Build and Deploy (service.xpcool.com) / build-and-deploy (push) Failing after 14s
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
// Package house_transaction 提供成交记录领域服务。
|
|
package house_transaction
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
|
|
"service.xpcool.com/internal/dao"
|
|
"service.xpcool.com/internal/model/dto"
|
|
)
|
|
|
|
// ITransaction 成交记录领域服务接口。
|
|
type ITransaction interface {
|
|
List(context.Context, int, int, string, string) ([]dto.HouseTransactionVO, int, error)
|
|
}
|
|
|
|
type transaction struct{}
|
|
|
|
var localTransaction ITransaction
|
|
|
|
func NewTransaction() ITransaction { return &transaction{} }
|
|
|
|
// Transaction 返回已注册的成交服务实现。
|
|
func Transaction() ITransaction {
|
|
if localTransaction == nil {
|
|
panic("Transaction implementation not registered")
|
|
}
|
|
return localTransaction
|
|
}
|
|
|
|
// RegisterTransaction 注册成交服务实现。
|
|
func RegisterTransaction(i ITransaction) { localTransaction = i }
|
|
|
|
// List 分页查询成交记录,关联小区名,按成交日期倒序。
|
|
func (s *transaction) List(ctx context.Context, page, size int, region, keyword string) ([]dto.HouseTransactionVO, int, error) {
|
|
m := dao.HouseTransaction.Ctx(ctx).As("t").
|
|
LeftJoin("house_community c", "t.community_id=c.id").
|
|
Fields("t.*, c.name AS community_name")
|
|
if region != "" {
|
|
m = m.Where("c.region", region)
|
|
}
|
|
if keyword != "" {
|
|
m = m.Where("c.name LIKE ? OR t.layout LIKE ?", "%"+keyword+"%", "%"+keyword+"%")
|
|
}
|
|
total, err := m.Clone().Count()
|
|
if err != nil {
|
|
return nil, 0, gerror.Wrap(err, "count transaction")
|
|
}
|
|
var list []dto.HouseTransactionVO
|
|
if err = m.Clone().Page(page, size).OrderDesc("t.deal_date").Scan(&list); err != nil {
|
|
return nil, 0, gerror.Wrap(err, "query transaction list")
|
|
}
|
|
return list, total, nil
|
|
}
|