|
@@ -10,13 +10,15 @@ import (
|
|
|
"eta/eta_api/models/system"
|
|
|
"eta/eta_api/utils"
|
|
|
"fmt"
|
|
|
- "github.com/rdlucklib/rdluck_tools/file"
|
|
|
- "github.com/rdlucklib/rdluck_tools/http"
|
|
|
"html"
|
|
|
"os"
|
|
|
"path"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
+
|
|
|
+ "github.com/go-redis/redis/v8"
|
|
|
+ "github.com/rdlucklib/rdluck_tools/file"
|
|
|
+ "github.com/rdlucklib/rdluck_tools/http"
|
|
|
)
|
|
|
|
|
|
// AddReportAndChapter
|
|
@@ -1496,3 +1498,57 @@ func GetReportWaterMarkPdf(reportInfo *models.Report, sysUser *system.Admin) {
|
|
|
waterMarkStr := fmt.Sprintf("%s - %s", sysUser.RealName, sysUser.Mobile)
|
|
|
GeneralWaterMarkPdf(filePath, waterMarkStr)
|
|
|
}
|
|
|
+
|
|
|
+// GetReportShareUrlToken 获取报告分享链接token
|
|
|
+func GetReportShareUrlToken(req models.ReportShartUrlReq) (linkToken string, err error) {
|
|
|
+ cacheLinkKey := utils.CACHE_REPORT_SHARE_SHORT_Url + strconv.Itoa(req.ReportId)
|
|
|
+ linkToken, _ = utils.Rc.RedisString(cacheLinkKey)
|
|
|
+ if linkToken != "" && utils.Rc.IsExist(utils.CACHE_REPORT_SHARE_ORIGIN_Url+linkToken) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var ok bool
|
|
|
+ // 冲突检测
|
|
|
+ for i := 0; i < 3; i++ {
|
|
|
+ linkToken = req.Url
|
|
|
+ if i > 0 {
|
|
|
+ linkToken += "_" + utils.GetRandDigit(3)
|
|
|
+ }
|
|
|
+ hashUrl := utils.MurmurHash64([]byte(linkToken))
|
|
|
+ linkToken = utils.ConvertNumToBase62(hashUrl)
|
|
|
+
|
|
|
+ ok = utils.Rc.IsExist(utils.CACHE_REPORT_SHARE_ORIGIN_Url + linkToken)
|
|
|
+ if !ok {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !ok {
|
|
|
+ after := time.Now().AddDate(0, 0, 7)
|
|
|
+ err = utils.Rc.Put(cacheLinkKey, linkToken, time.Until(after))
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = utils.Rc.Put(utils.CACHE_REPORT_SHARE_ORIGIN_Url+linkToken, req.Url, time.Until(after))
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func TransfromToOriginUrl(linkToken string) (originLink string, msg string, err error) {
|
|
|
+ cacheLinkKey := utils.CACHE_REPORT_SHARE_ORIGIN_Url + linkToken
|
|
|
+ originLink, err = utils.Rc.RedisString(cacheLinkKey)
|
|
|
+ if err != nil {
|
|
|
+ if err == redis.Nil {
|
|
|
+ msg = "链接已失效, 请重新获取"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ msg = "获取链接失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if originLink == "" {
|
|
|
+ msg = "链接已失效, 请重新获取"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|