fix: 优化负利润分析报表处理逻辑
This commit is contained in:
parent
c91e7bc95b
commit
c7e1bad7ef
|
|
@ -45,7 +45,7 @@ func (s *SessionBiz) SessionInit(ctx context.Context, req *entitys.SessionInitRe
|
||||||
|
|
||||||
// 获取 当天的最新session
|
// 获取 当天的最新session
|
||||||
t := time.Now().Truncate(24 * time.Hour)
|
t := time.Now().Truncate(24 * time.Hour)
|
||||||
session, has, err := s.sessionRepo.FindOne(
|
session, has, err := s.sessionRepo.Take(
|
||||||
s.sessionRepo.WithUserId(req.UserId), // 条件:用户ID
|
s.sessionRepo.WithUserId(req.UserId), // 条件:用户ID
|
||||||
s.sessionRepo.WithStartTime(t), // 条件:会话开始时间
|
s.sessionRepo.WithStartTime(t), // 条件:会话开始时间
|
||||||
s.sysRepo.WithSysId(sysConfig.SysID),
|
s.sysRepo.WithSysId(sysConfig.SysID),
|
||||||
|
|
|
||||||
|
|
@ -43,20 +43,21 @@ type BaseRepository[P PO] interface {
|
||||||
FindAll(conditions ...CondFunc) ([]P, error) // 查询所有
|
FindAll(conditions ...CondFunc) ([]P, error) // 查询所有
|
||||||
Paginate(page, pageSize int, conditions ...CondFunc) (*PaginationResult[P], error) // 分页查询
|
Paginate(page, pageSize int, conditions ...CondFunc) (*PaginationResult[P], error) // 分页查询
|
||||||
FindOne(conditions ...CondFunc) (P, bool, error) // 查询单条记录,若未找到则返回 has=false, err=nil
|
FindOne(conditions ...CondFunc) (P, bool, error) // 查询单条记录,若未找到则返回 has=false, err=nil
|
||||||
Create(m *P) error // 创建
|
Take(conditions ...CondFunc) (P, bool, error)
|
||||||
BatchCreate(m *[]P) (err error) // 批量创建
|
Create(m *P) error // 创建
|
||||||
Update(m *P, conditions ...CondFunc) (err error) // 更新
|
BatchCreate(m *[]P) (err error) // 批量创建
|
||||||
Delete(conditions ...CondFunc) (err error) // 删除
|
Update(m *P, conditions ...CondFunc) (err error) // 更新
|
||||||
Count(conditions ...CondFunc) (count int64, err error) // 查询条数
|
Delete(conditions ...CondFunc) (err error) // 删除
|
||||||
PaginateScope(page, pageSize int) CondFunc // 分页
|
Count(conditions ...CondFunc) (count int64, err error) // 查询条数
|
||||||
OrderByDesc(field string) CondFunc // 倒序排序
|
PaginateScope(page, pageSize int) CondFunc // 分页
|
||||||
OrderByAsc(field string) CondFunc // 正序排序
|
OrderByDesc(field string) CondFunc // 倒序排序
|
||||||
WithId(id interface{}) CondFunc // 查询id
|
OrderByAsc(field string) CondFunc // 正序排序
|
||||||
WithStatus(status int) CondFunc // 查询status
|
WithId(id interface{}) CondFunc // 查询id
|
||||||
GetDb() *gorm.DB // 获取数据库连接
|
WithStatus(status int) CondFunc // 查询status
|
||||||
WithLimit(limit int) CondFunc // 限制返回条数
|
GetDb() *gorm.DB // 获取数据库连接
|
||||||
In(field string, values interface{}) CondFunc // 查询字段是否在列表中
|
WithLimit(limit int) CondFunc // 限制返回条数
|
||||||
Select(fields ...string) CondFunc // 选择字段
|
In(field string, values interface{}) CondFunc // 查询字段是否在列表中
|
||||||
|
Select(fields ...string) CondFunc // 选择字段
|
||||||
}
|
}
|
||||||
|
|
||||||
// PaginationResult 分页查询结果
|
// PaginationResult 分页查询结果
|
||||||
|
|
@ -128,6 +129,26 @@ func (this *BaseModel[P]) FindOne(conditions ...CondFunc) (P, bool, error) {
|
||||||
return result, true, err
|
return result, true, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *BaseModel[P]) Take(conditions ...CondFunc) (P, bool, error) {
|
||||||
|
var (
|
||||||
|
result P
|
||||||
|
)
|
||||||
|
|
||||||
|
err := this.Db.Model(new(P)).
|
||||||
|
Scopes(conditions...).
|
||||||
|
Take(&result).
|
||||||
|
Error
|
||||||
|
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return result, false, nil // 未找到记录
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return result, false, fmt.Errorf("查询单条记录失败: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, true, err
|
||||||
|
}
|
||||||
|
|
||||||
// 创建
|
// 创建
|
||||||
func (this *BaseModel[P]) Create(m *P) error {
|
func (this *BaseModel[P]) Create(m *P) error {
|
||||||
err := this.Db.Create(m).Error
|
err := this.Db.Create(m).Error
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue