Some checks failed
Build and Deploy (service.xpcool.com) / build-and-deploy (push) Failing after 31s
将 api 层校验规则提示语、service 层 gerror.Wrap 与 response.Error 错误信息、panic 未注册提示统一改为中文,并同步中文化 cmd 路由注释 与变更记录。仅涉及注释、文档与字符串改动,无业务逻辑变更。
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
// Package house_presale 提供新房预售证领域服务。
|
|
package house_presale
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
|
|
"service.xpcool.com/internal/dao"
|
|
"service.xpcool.com/internal/model/dto"
|
|
)
|
|
|
|
// IPresale 新房预售证领域服务接口。
|
|
type IPresale interface {
|
|
List(context.Context, int, int, string, string, string) ([]dto.HousePresaleVO, int, error)
|
|
}
|
|
|
|
type presale struct{}
|
|
|
|
var localPresale IPresale
|
|
|
|
func NewPresale() IPresale { return &presale{} }
|
|
|
|
// Presale 返回已注册的预售证服务实现。
|
|
func Presale() IPresale {
|
|
if localPresale == nil {
|
|
panic("Presale 实现未注册")
|
|
}
|
|
return localPresale
|
|
}
|
|
|
|
// RegisterPresale 注册预售证服务实现。
|
|
func RegisterPresale(i IPresale) { localPresale = i }
|
|
|
|
// List 分页查询新房预售证,按 id 倒序(最新发证在前)。
|
|
func (s *presale) List(ctx context.Context, page, size int, region, keyword, purpose string) ([]dto.HousePresaleVO, int, error) {
|
|
m := dao.HousePresale.Ctx(ctx)
|
|
if region != "" {
|
|
m = m.Where("region", region)
|
|
}
|
|
if purpose != "" {
|
|
m = m.Where("purpose", purpose)
|
|
}
|
|
if keyword != "" {
|
|
m = m.Where("community_name LIKE ? OR developer LIKE ? OR presale_no LIKE ?",
|
|
"%"+keyword+"%", "%"+keyword+"%", "%"+keyword+"%")
|
|
}
|
|
total, err := m.Clone().Count()
|
|
if err != nil {
|
|
return nil, 0, gerror.Wrap(err, "统计预售证总数失败")
|
|
}
|
|
var list []dto.HousePresaleVO
|
|
if err = m.Clone().Page(page, size).OrderDesc("id").Scan(&list); err != nil {
|
|
return nil, 0, gerror.Wrap(err, "查询预售证列表失败")
|
|
}
|
|
return list, total, nil
|
|
}
|