service.xpcool.com/internal/service/house/community/community.go
夏犀麟 4aca0c7f6f
Some checks failed
Build and Deploy (service.xpcool.com) / build-and-deploy (push) Failing after 5m7s
feat(house): 实现看房模块后端功能
- 新增 9 张房屋相关数据表(社区/楼宇/房源/价格快照/交易/设施/社区设施/学区/偏好)
- 添加菜单权限种子数据并绑定超级管理员角色
- 生成 DAO 层代码和实体对象
- 实现房屋模块 API 接口(社区/房源/看板)和控制器服务层
- 支持多平台软关联匹配、笋盘标记和低可信度标记功能
- 更新超级管理员账号为 xxcool/xxCool@2026
- 调整 RBAC 菜单结构,移除管理员管理功能,新增日志管理菜单
- 修复 RBAC 安全漏洞,确保禁用角色权限失效
- 重构认证模块,将登录相关接口迁移到统一包结构下
- 移除废弃的管理模块和工具类接口定义
- 为通用工具包添加中文注释和文档说明
2026-08-26 23:42:38 +08:00

114 lines
3.4 KiB
Go

// Package house_community 提供楼盘/小区领域服务。
package house_community
import (
"context"
"github.com/gogf/gf/v2/errors/gerror"
"service.xpcool.com/internal/dao"
"service.xpcool.com/internal/model/do"
"service.xpcool.com/internal/model/dto"
"service.xpcool.com/internal/model/entity"
)
// ICommunity 小区/楼盘领域服务接口。
type ICommunity interface {
List(context.Context, int, int, string, string) ([]entity.HouseCommunity, int, error)
Create(context.Context, dto.HouseCommunityInput) (uint64, error)
Update(context.Context, dto.HouseCommunityInput) error
Delete(context.Context, uint64) error
}
type community struct{}
var localCommunity ICommunity
func NewCommunity() ICommunity { return &community{} }
// Community 返回已注册的小区服务实现。
func Community() ICommunity {
if localCommunity == nil {
panic("Community implementation not registered")
}
return localCommunity
}
// RegisterCommunity 注册小区服务实现。
func RegisterCommunity(i ICommunity) { localCommunity = i }
// List 分页查询小区,支持关键字(名称)与区域过滤。
func (s *community) List(ctx context.Context, page, size int, keyword, region string) ([]entity.HouseCommunity, int, error) {
m := dao.HouseCommunity.Ctx(ctx)
if keyword != "" {
m = m.WhereLike("name", "%"+keyword+"%")
}
if region != "" {
m = m.Where("region", region)
}
total, err := m.Clone().Count()
if err != nil {
return nil, 0, gerror.Wrap(err, "count community")
}
var list []entity.HouseCommunity
if err = m.Clone().Page(page, size).OrderDesc("id").Scan(&list); err != nil {
return nil, 0, gerror.Wrap(err, "query community list")
}
return list, total, nil
}
// Create 新增小区。
func (s *community) Create(ctx context.Context, in dto.HouseCommunityInput) (uint64, error) {
id, err := dao.HouseCommunity.Ctx(ctx).Data(do.HouseCommunity{
Name: in.Name,
Region: in.Region,
BusinessDistrict: in.BusinessDistrict,
Address: in.Address,
Lng: in.Lng,
Lat: in.Lat,
BuildYear: in.BuildYear,
Households: in.Households,
PlotRatio: in.PlotRatio,
GreenRate: in.GreenRate,
PropertyCompany: in.PropertyCompany,
PropertyFee: in.PropertyFee,
Developer: in.Developer,
Source: in.Source,
}).InsertAndGetId()
if err != nil {
return 0, gerror.Wrap(err, "insert community")
}
return uint64(id), nil
}
// Update 更新小区。
func (s *community) Update(ctx context.Context, in dto.HouseCommunityInput) error {
_, err := dao.HouseCommunity.Ctx(ctx).Where(do.HouseCommunity{Id: in.Id}).Data(do.HouseCommunity{
Name: in.Name,
Region: in.Region,
BusinessDistrict: in.BusinessDistrict,
Address: in.Address,
Lng: in.Lng,
Lat: in.Lat,
BuildYear: in.BuildYear,
Households: in.Households,
PlotRatio: in.PlotRatio,
GreenRate: in.GreenRate,
PropertyCompany: in.PropertyCompany,
PropertyFee: in.PropertyFee,
Developer: in.Developer,
}).Update()
if err != nil {
return gerror.Wrap(err, "update community")
}
return nil
}
// Delete 软删除小区。
func (s *community) Delete(ctx context.Context, id uint64) error {
if _, err := dao.HouseCommunity.Ctx(ctx).Where(do.HouseCommunity{Id: id}).Delete(); err != nil {
return gerror.Wrap(err, "delete community")
}
return nil
}