Some checks failed
Build and Deploy (service.xpcool.com) / build-and-deploy (push) Failing after 31s
将 api 层校验规则提示语、service 层 gerror.Wrap 与 response.Error 错误信息、panic 未注册提示统一改为中文,并同步中文化 cmd 路由注释 与变更记录。仅涉及注释、文档与字符串改动,无业务逻辑变更。
55 lines
1.6 KiB
Go
55 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 实现未注册")
|
|
}
|
|
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")
|
|
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, "统计成交记录总数失败")
|
|
}
|
|
var list []dto.HouseTransactionVO
|
|
if err = m.Clone().Fields("t.*, c.name AS community_name").Page(page, size).OrderDesc("t.deal_date").Scan(&list); err != nil {
|
|
return nil, 0, gerror.Wrap(err, "查询成交记录列表失败")
|
|
}
|
|
return list, total, nil
|
|
}
|