|
|
@@ -3,12 +3,15 @@ package comm |
|
|
|
import ( |
|
|
|
"applet/app/db" |
|
|
|
"applet/app/e" |
|
|
|
"applet/app/md" |
|
|
|
"applet/app/md/comm" |
|
|
|
"applet/app/svc" |
|
|
|
"applet/app/utils" |
|
|
|
"applet/app/utils/cache" |
|
|
|
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" |
|
|
|
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" |
|
|
|
enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" |
|
|
|
"fmt" |
|
|
|
"github.com/aliyun/aliyun-oss-go-sdk/oss" |
|
|
|
"github.com/gin-gonic/gin" |
|
|
|
"time" |
|
|
@@ -103,24 +106,42 @@ func AccessRecords(c *gin.Context) { |
|
|
|
|
|
|
|
user := svc.GetUser(c) |
|
|
|
date := time.Now().Format("2006-01-02") |
|
|
|
recordsDb := implement.NewEggAccessRecordsDb(db.Db) |
|
|
|
exist, err := recordsDb.EggAccessRecordsExist(user.Id, date, req.Index) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, nil) |
|
|
|
} |
|
|
|
if exist { |
|
|
|
e.OutSuc(c, "data exist", nil) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
m := model.EggAccessRecords{ |
|
|
|
Uid: user.Id, |
|
|
|
PageIndex: req.Index, |
|
|
|
Date: date, |
|
|
|
} |
|
|
|
_, err = recordsDb.EggAccessRecordsInsert(&m) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, nil) |
|
|
|
cacheKey := fmt.Sprintf(md.UserAccessRecordsKey, user.Id, date, req.Index) |
|
|
|
get, err1 := cache.GetString(cacheKey) |
|
|
|
if err1 != nil || get == "" { |
|
|
|
recordsDb := implement.NewEggAccessRecordsDb(db.Db) |
|
|
|
exist, err := recordsDb.EggAccessRecordsExist(user.Id, date, req.Index) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, nil) |
|
|
|
} |
|
|
|
if exist { |
|
|
|
e.OutSuc(c, "success", nil) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
m := model.EggAccessRecords{ |
|
|
|
Uid: user.Id, |
|
|
|
PageIndex: req.Index, |
|
|
|
Date: date, |
|
|
|
} |
|
|
|
_, err = recordsDb.EggAccessRecordsInsert(&m) |
|
|
|
if err != nil { |
|
|
|
e.OutErr(c, e.ERR_DB_ORM, nil) |
|
|
|
return |
|
|
|
} |
|
|
|
ttl := 3 * 60 * 60 // 记录保存三小时 |
|
|
|
|
|
|
|
_, err = cache.SetEx(cacheKey, "1", ttl) |
|
|
|
if err != nil { |
|
|
|
fmt.Println("AccessRecordsRedis_ERR:::::", err.Error()) |
|
|
|
utils.FilePutContents("AccessRecordsRedis_ERR", utils.SerializeStr(map[string]interface{}{ |
|
|
|
"cacheKey": cacheKey, |
|
|
|
"err": err.Error(), |
|
|
|
})) |
|
|
|
} |
|
|
|
} else { |
|
|
|
e.OutSuc(c, "success", nil) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|