Finish the PageHandle for matter.
This commit is contained in:
		| @ -57,8 +57,6 @@ func (this *DashboardService) Bootstrap() { | |||||||
| // handle the dashboard data. | // handle the dashboard data. | ||||||
| func (this *DashboardService) Etl() { | func (this *DashboardService) Etl() { | ||||||
|  |  | ||||||
| 	this.logger.Info("ETL dashboard data.") |  | ||||||
|  |  | ||||||
| 	startTime := util.FirstSecondOfDay(util.Yesterday()) | 	startTime := util.FirstSecondOfDay(util.Yesterday()) | ||||||
| 	endTime := util.LastSecondOfDay(util.Yesterday()) | 	endTime := util.LastSecondOfDay(util.Yesterday()) | ||||||
| 	dt := util.ConvertTimeToDateString(startTime) | 	dt := util.ConvertTimeToDateString(startTime) | ||||||
|  | |||||||
| @ -7,6 +7,7 @@ import ( | |||||||
| 	"github.com/eyebluecn/tank/code/tool/util" | 	"github.com/eyebluecn/tank/code/tool/util" | ||||||
| 	"github.com/eyebluecn/tank/code/tool/uuid" | 	"github.com/eyebluecn/tank/code/tool/uuid" | ||||||
| 	"github.com/jinzhu/gorm" | 	"github.com/jinzhu/gorm" | ||||||
|  | 	"math" | ||||||
| 	"os" | 	"os" | ||||||
| 	"time" | 	"time" | ||||||
| ) | ) | ||||||
| @ -298,6 +299,31 @@ func (this *MatterDao) Page(page int, pageSize int, puuid string, userUuid strin | |||||||
| 	return pager | 	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 { | func (this *MatterDao) Create(matter *Matter) *Matter { | ||||||
|  |  | ||||||
| 	timeUUID, _ := uuid.NewV4() | 	timeUUID, _ := uuid.NewV4() | ||||||
|  | |||||||
| @ -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) | ||||||
|  |  | ||||||
|  | } | ||||||
|  | |||||||
| @ -5,6 +5,7 @@ import ( | |||||||
| 	"github.com/eyebluecn/tank/code/tool/result" | 	"github.com/eyebluecn/tank/code/tool/result" | ||||||
| 	"github.com/eyebluecn/tank/code/tool/util" | 	"github.com/eyebluecn/tank/code/tool/util" | ||||||
| 	jsoniter "github.com/json-iterator/go" | 	jsoniter "github.com/json-iterator/go" | ||||||
|  | 	"github.com/robfig/cron/v3" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"strconv" | 	"strconv" | ||||||
| ) | ) | ||||||
| @ -157,7 +158,19 @@ func (this *PreferenceController) EditScanConfig(writer http.ResponseWriter, req | |||||||
| 	//validate the scan config. | 	//validate the scan config. | ||||||
| 	if scanConfig.Enable { | 	if scanConfig.Enable { | ||||||
| 		//validate cron. | 		//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) | 	preference = this.preferenceService.Save(preference) | ||||||
|  | |||||||
| @ -37,7 +37,7 @@ const ( | |||||||
| type ScanConfig struct { | type ScanConfig struct { | ||||||
| 	//whether enable the scan task. | 	//whether enable the scan task. | ||||||
| 	Enable bool `json:"enable"` | 	Enable bool `json:"enable"` | ||||||
| 	//when to process the task. | 	//when to process the task. five fields. @every 1s | ||||||
| 	Cron string `json:"cron"` | 	Cron string `json:"cron"` | ||||||
| 	//username | 	//username | ||||||
| 	Usernames []string `json:"usernames"` | 	Usernames []string `json:"usernames"` | ||||||
|  | |||||||
| @ -118,6 +118,7 @@ func (this *ShareService) DeleteSharesByUser(request *http.Request, currentUser | |||||||
| 	pageSize := 100 | 	pageSize := 100 | ||||||
| 	var sortArray []builder.OrderPair | 	var sortArray []builder.OrderPair | ||||||
| 	count, _ := this.shareDao.PlainPage(0, pageSize, currentUser.Uuid, sortArray) | 	count, _ := this.shareDao.PlainPage(0, pageSize, currentUser.Uuid, sortArray) | ||||||
|  | 	if count > 0 { | ||||||
| 		var totalPages = int(math.Ceil(float64(count) / float64(pageSize))) | 		var totalPages = int(math.Ceil(float64(count) / float64(pageSize))) | ||||||
|  |  | ||||||
| 		var page int | 		var page int | ||||||
| @ -132,3 +133,5 @@ func (this *ShareService) DeleteSharesByUser(request *http.Request, currentUser | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | } | ||||||
|  | |||||||
| @ -16,6 +16,7 @@ type UserController struct { | |||||||
| 	BaseController | 	BaseController | ||||||
| 	preferenceService *PreferenceService | 	preferenceService *PreferenceService | ||||||
| 	userService       *UserService | 	userService       *UserService | ||||||
|  | 	matterService     *MatterService | ||||||
| } | } | ||||||
|  |  | ||||||
| func (this *UserController) Init() { | func (this *UserController) Init() { | ||||||
| @ -31,6 +32,11 @@ func (this *UserController) Init() { | |||||||
| 		this.userService = b | 		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) { | 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/page"] = this.Wrap(this.Page, USER_ROLE_ADMINISTRATOR) | ||||||
| 	routeMap["/api/user/toggle/status"] = this.Wrap(this.ToggleStatus, 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/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) | 	routeMap["/api/user/delete"] = this.Wrap(this.Delete, USER_ROLE_ADMINISTRATOR) | ||||||
|  |  | ||||||
| 	return routeMap | 	return routeMap | ||||||
| @ -432,6 +439,16 @@ func (this *UserController) Transfiguration(writer http.ResponseWriter, request | |||||||
| 	return this.Success(session.Uuid) | 	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 { | func (this *UserController) Delete(writer http.ResponseWriter, request *http.Request) *result.WebResult { | ||||||
|  |  | ||||||
| 	uuid := request.FormValue("uuid") | 	uuid := request.FormValue("uuid") | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user