소스 검색

添加文件列表总数

chengqian 9 달 전
부모
커밋
5ba8565f34
2개의 변경된 파일8개의 추가작업 그리고 8개의 파일을 삭제
  1. 6 6
      app/file/dao/file.go
  2. 2 2
      app/file/service/fileService.go

+ 6 - 6
app/file/dao/file.go

@@ -33,11 +33,10 @@ func (f *File) Create() error {
 	return Db.Model(&f).Save(&f).Error
 }
 
-func (f *File) GetSysUserFiles(uid int, search model.SearchSysUserFiles) ([]File, error) {
-	var files []File
+func (f *File) GetSysUserFiles(uid int, search model.SearchSysUserFiles) (files []File, total int64, err error) {
 	//var db *gorm.DB
 	db := Db.Table("file").
-		Select("file.*").
+		Select("file.id,file.*").
 		Joins("left join user_file uf on uf.file_id = file.id").
 		Where("uf.receiver = ? AND file.is_showed = 0 AND file.is_deleted = 0 AND uf.is_deleted = 0 AND uf.operation_status = '下发' OR uf.operation_status = '转发'", uid). // 根据upload_time字段降序排列
 		Group("file.id")
@@ -55,12 +54,13 @@ func (f *File) GetSysUserFiles(uid int, search model.SearchSysUserFiles) ([]File
 	}
 	limit := search.PageSize
 	offset := search.PageSize * (search.PageNO - 1)
+	db.Count(&total)
 	// 执行查询并检查错误
-	err := db.Limit(limit).Offset(offset).Scan(&files).Error
+	err = db.Limit(limit).Offset(offset).Scan(&files).Error
 	if err != nil {
-		return nil, err
+		return nil, 0, err
 	}
-	return files, err
+	return files, total, err
 }
 
 func (f *File) GetFileInfo(fileid, uid int) (model.RespFileInfo, error) {

+ 2 - 2
app/file/service/fileService.go

@@ -61,11 +61,11 @@ func (f *fileService) Distribute(requserfile *model.ReqSysUserFile, uid int) *co
 func (f *fileService) GetSysUserFiles(id string, search model.SearchSysUserFiles) *common.Errors {
 	filedao := &dao.File{}
 	uid, _ := strconv.Atoi(id)
-	files, err := filedao.GetSysUserFiles(uid, search)
+	files, total, err := filedao.GetSysUserFiles(uid, search)
 	if err != nil {
 		return common.FailResponse(err.Error(), nil)
 	}
-	return common.SuccessResponse("查询成功", gin.H{"files": files})
+	return common.SuccessResponse("查询成功", gin.H{"files": files, "total": total})
 }
 
 func (f *fileService) GetFile(id string, c *gin.Context) {