Finish the PageHandle for matter.

This commit is contained in:
lishuang 2020-07-11 17:42:09 +08:00
parent 192df21da4
commit f16d48b432
7 changed files with 94 additions and 11 deletions

View File

@ -57,8 +57,6 @@ func (this *DashboardService) Bootstrap() {
// handle the dashboard data.
func (this *DashboardService) Etl() {
this.logger.Info("ETL dashboard data.")
startTime := util.FirstSecondOfDay(util.Yesterday())
endTime := util.LastSecondOfDay(util.Yesterday())
dt := util.ConvertTimeToDateString(startTime)

View File

@ -7,6 +7,7 @@ import (
"github.com/eyebluecn/tank/code/tool/util"
"github.com/eyebluecn/tank/code/tool/uuid"
"github.com/jinzhu/gorm"
"math"
"os"
"time"
)
@ -298,6 +299,31 @@ func (this *MatterDao) Page(page int, pageSize int, puuid string, userUuid strin
return pager
}
//handle matter page by page.
func (this *MatterDao) PageHandle(puuid string, userUuid string, name string, dir string, fun func(matter *Matter)) {
//delete share and bridges.
pageSize := 1000
sortArray := []builder.OrderPair{
{
Key: "uuid",
Value: DIRECTION_ASC,
},
}
count, _ := this.PlainPage(0, pageSize, puuid, userUuid, name, dir, nil, sortArray)
if count > 0 {
var totalPages = int(math.Ceil(float64(count) / float64(pageSize)))
var page int
for page = 0; page < totalPages; page++ {
_, matters := this.PlainPage(0, pageSize, puuid, userUuid, name, dir, nil, sortArray)
for _, matter := range matters {
fun(matter)
}
}
}
}
func (this *MatterDao) Create(matter *Matter) *Matter {
timeUUID, _ := uuid.NewV4()

View File

@ -1049,3 +1049,29 @@ func (this *MatterService) adjustPath(matter *Matter, parentMatter *Matter) {
}
}
//delete someone's EyeblueTank files according to physics files.
func (this *MatterService) DeleteByPhysics(user *User) {
if user == nil {
panic(result.BadRequest("user cannot be nil."))
}
//scan user's file.
this.matterDao.PageHandle("", user.Uuid, "", "", func(matter *Matter) {
this.logger.Info("handle %s", matter.Name)
})
}
//scan someone's physics files to EyeblueTank
func (this *MatterService) Scan(user *User) {
if user == nil {
panic(result.BadRequest("user cannot be nil."))
}
rootDirPath := GetUserMatterRootDir(user.Username)
this.logger.Info("scan %s's root dir %s", user.Username, rootDirPath)
}

View File

@ -5,6 +5,7 @@ import (
"github.com/eyebluecn/tank/code/tool/result"
"github.com/eyebluecn/tank/code/tool/util"
jsoniter "github.com/json-iterator/go"
"github.com/robfig/cron/v3"
"net/http"
"strconv"
)
@ -157,7 +158,19 @@ func (this *PreferenceController) EditScanConfig(writer http.ResponseWriter, req
//validate the scan config.
if scanConfig.Enable {
//validate cron.
_, err := cron.ParseStandard(scanConfig.Cron)
this.PanicError(err)
//validate scope.
if scanConfig.Scope == SCAN_SCOPE_CUSTOM {
if len(scanConfig.Usernames) == 0 {
panic(result.BadRequest("scope cannot be null"))
}
} else if scanConfig.Scope == SCAN_SCOPE_ALL {
} else {
panic(result.BadRequest("cannot recognize scope %s", scanConfig.Scope))
}
}
preference = this.preferenceService.Save(preference)

View File

@ -37,7 +37,7 @@ const (
type ScanConfig struct {
//whether enable the scan task.
Enable bool `json:"enable"`
//when to process the task.
//when to process the task. five fields. @every 1s
Cron string `json:"cron"`
//username
Usernames []string `json:"usernames"`

View File

@ -118,6 +118,7 @@ func (this *ShareService) DeleteSharesByUser(request *http.Request, currentUser
pageSize := 100
var sortArray []builder.OrderPair
count, _ := this.shareDao.PlainPage(0, pageSize, currentUser.Uuid, sortArray)
if count > 0 {
var totalPages = int(math.Ceil(float64(count) / float64(pageSize)))
var page int
@ -131,4 +132,6 @@ func (this *ShareService) DeleteSharesByUser(request *http.Request, currentUser
}
}
}
}

View File

@ -16,6 +16,7 @@ type UserController struct {
BaseController
preferenceService *PreferenceService
userService *UserService
matterService *MatterService
}
func (this *UserController) Init() {
@ -31,6 +32,11 @@ func (this *UserController) Init() {
this.userService = b
}
b = core.CONTEXT.GetBean(this.matterService)
if b, ok := b.(*MatterService); ok {
this.matterService = b
}
}
func (this *UserController) RegisterRoutes() map[string]func(writer http.ResponseWriter, request *http.Request) {
@ -50,6 +56,7 @@ func (this *UserController) RegisterRoutes() map[string]func(writer http.Respons
routeMap["/api/user/page"] = this.Wrap(this.Page, USER_ROLE_ADMINISTRATOR)
routeMap["/api/user/toggle/status"] = this.Wrap(this.ToggleStatus, USER_ROLE_ADMINISTRATOR)
routeMap["/api/user/transfiguration"] = this.Wrap(this.Transfiguration, USER_ROLE_ADMINISTRATOR)
routeMap["/api/user/scan"] = this.Wrap(this.Scan, USER_ROLE_ADMINISTRATOR)
routeMap["/api/user/delete"] = this.Wrap(this.Delete, USER_ROLE_ADMINISTRATOR)
return routeMap
@ -432,6 +439,16 @@ func (this *UserController) Transfiguration(writer http.ResponseWriter, request
return this.Success(session.Uuid)
}
//scan user's physics files. create index into EyeblueTank
func (this *UserController) Scan(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid")
currentUser := this.userDao.CheckByUuid(uuid)
this.matterService.Scan(currentUser)
return this.Success("OK")
}
func (this *UserController) Delete(writer http.ResponseWriter, request *http.Request) *result.WebResult {
uuid := request.FormValue("uuid")