Finish half translation work.

This commit is contained in:
zicla
2019-05-04 23:36:05 +08:00
parent 900924d196
commit 5625149766
52 changed files with 613 additions and 950 deletions

View File

@ -17,11 +17,9 @@ type FootprintService struct {
userDao *UserDao
}
//初始化方法
func (this *FootprintService) Init() {
this.BaseBean.Init()
//手动装填本实例的Bean. 这里必须要用中间变量方可。
b := core.CONTEXT.GetBean(this.footprintDao)
if b, ok := b.(*FootprintDao); ok {
this.footprintDao = b
@ -34,7 +32,6 @@ func (this *FootprintService) Init() {
}
//获取某个文件的详情,会把父级依次倒着装进去。如果中途出错,直接抛出异常。
func (this *FootprintService) Detail(uuid string) *Footprint {
footprint := this.footprintDao.CheckByUuid(uuid)
@ -42,17 +39,17 @@ func (this *FootprintService) Detail(uuid string) *Footprint {
return footprint
}
//记录访问记录
//log a request.
func (this *FootprintService) Trace(request *http.Request, duration time.Duration, success bool) {
params := make(map[string][]string)
//POST请求参数
//POST params
values := request.PostForm
for key, val := range values {
params[key] = val
}
//GET请求参数
//GET params
values1 := request.URL.Query()
for key, val := range values1 {
params[key] = val
@ -65,14 +62,12 @@ func (this *FootprintService) Trace(request *http.Request, duration time.Duratio
}
}
//用json的方式输出返回值。
paramsString := "{}"
paramsData, err := json.Marshal(params)
if err == nil {
paramsString = string(paramsData)
}
//将文件信息存入数据库中。
footprint := &Footprint{
Ip: util.GetIpAddress(request),
Host: request.Host,
@ -82,7 +77,7 @@ func (this *FootprintService) Trace(request *http.Request, duration time.Duratio
Success: success,
}
//有可能DB尚且没有配置 直接打印出内容,并且退出
//if db not config just print content.
if core.CONFIG.Installed() {
user := this.findUser(request)
userUuid := ""
@ -93,35 +88,30 @@ func (this *FootprintService) Trace(request *http.Request, duration time.Duratio
footprint = this.footprintDao.Create(footprint)
}
//用json的方式输出返回值。
this.logger.Info("Ip:%s Cost:%d Uri:%s Params:%s", footprint.Ip, int64(duration/time.Millisecond), footprint.Uri, paramsString)
}
//系统启动,数据库配置完毕后会调用该方法
func (this *FootprintService) Bootstrap() {
//每日00:10 删除8日之前的访问数据
this.logger.Info("[cron job] Every day 00:10 delete Footprint data 8 days ago.")
expression := "0 10 0 * * ?"
cronJob := cron.New()
err := cronJob.AddFunc(expression, this.cleanOldData)
core.PanicError(err)
cronJob.Start()
this.logger.Info("[cron job] 每日00:10 删除8日之前的访问数据")
//立即执行一次数据清洗任务
go core.RunWithRecovery(this.cleanOldData)
}
//定期删除8日前的数据。
func (this *FootprintService) cleanOldData() {
day8Ago := time.Now()
day8Ago = day8Ago.AddDate(0, 0, -8)
day8Ago = util.FirstSecondOfDay(day8Ago)
this.logger.Info("删除%s之前的访问数据", util.ConvertTimeToDateTimeString(day8Ago))
this.logger.Info("Delete footprint data before %s", util.ConvertTimeToDateTimeString(day8Ago))
this.footprintDao.DeleteByCreateTimeBefore(day8Ago)
}