蛋蛋星球-客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_comm.go 4.1 KiB

1 month ago
1 month ago
1 month ago
1 week ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 week ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
1 month ago
4 weeks ago
4 weeks ago
4 weeks ago
1 month ago
1 month ago
1 week ago
1 month ago
1 month ago
1 month ago
1 month ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package comm
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/md/comm"
  7. "applet/app/svc"
  8. "applet/app/svc/sys_cfg"
  9. "applet/app/utils"
  10. "applet/app/utils/cache"
  11. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  12. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  13. enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  14. "fmt"
  15. "github.com/aliyun/aliyun-oss-go-sdk/oss"
  16. "github.com/gin-gonic/gin"
  17. "time"
  18. )
  19. // GetOssUrl
  20. // @Summary 通用请求-对象存储-上传许可链接(获取)
  21. // @Tags 对象存储
  22. // @Description 上传许可链接(获取)
  23. // @Accept json
  24. // @Produce json
  25. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  26. // @Param req body comm.ImgReqUploadReq true "签名上传url"
  27. // @Success 200 {string} "许可链接"
  28. // @Failure 400 {object} md.Response "具体错误"
  29. // @Router /api/v1/comm/getOssUrl [POST]
  30. func GetOssUrl(c *gin.Context) {
  31. var args comm.ImgReqUploadReq
  32. err := c.ShouldBindJSON(&args)
  33. if err != nil {
  34. err = svc.HandleValidateErr(err)
  35. err1 := err.(e.E)
  36. e.OutErr(c, err1.Code, err1.Error())
  37. return
  38. }
  39. sysCfgDb := sys_cfg.NewSysCfgDb(db.Db)
  40. sysCfgs, err := sysCfgDb.SysCfgGetAll()
  41. if err != nil {
  42. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  43. return
  44. }
  45. if sysCfgs == nil {
  46. e.OutErr(c, e.ERR_CFG_CACHE, nil)
  47. return
  48. }
  49. cfgMap := make(map[string]string, len(*sysCfgs))
  50. for _, cfg := range *sysCfgs {
  51. cfgMap[cfg.Key] = cfg.Val
  52. }
  53. endpoint := cfgMap[enum2.AliyunOssEndpoint]
  54. bucketName := cfgMap[enum2.AliyunOssBucketName]
  55. ossBucketScheme := cfgMap[enum2.AliyunOssBucketScheme]
  56. accessKeyID := cfgMap[enum2.AliyunOssAccessKeyID]
  57. accessKeySecret := cfgMap[enum2.AliyunOssAccessKeySecret]
  58. // 创建OSSClient实例。
  59. client, err := oss.New(ossBucketScheme+"://"+endpoint, accessKeyID, accessKeySecret)
  60. if err != nil {
  61. e.OutErr(c, e.ERR, err.Error())
  62. return
  63. }
  64. // 获取存储空间。
  65. bucket, err := client.Bucket(bucketName)
  66. if err != nil {
  67. e.OutErr(c, e.ERR, err.Error())
  68. return
  69. }
  70. options := []oss.Option{
  71. oss.ContentType(args.ContentType),
  72. }
  73. signedURL, err := bucket.SignURL(args.FileName, oss.HTTPPut, 60*5, options...)
  74. if err != nil {
  75. e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
  76. return
  77. }
  78. e.OutSuc(c, signedURL, nil)
  79. }
  80. // AccessRecords
  81. // @Summary 通用请求-访问记录-页面记录
  82. // @Tags 访问记录
  83. // @Description 页面记录
  84. // @Accept json
  85. // @Produce json
  86. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  87. // @Param req body comm.AccessRecordsReq true "页面标识"
  88. // @Success 200 {string} "success"
  89. // @Success 200 {string} "data exist"
  90. // @Failure 400 {object} md.Response "具体错误"
  91. // @Router /api/v1/comm/accessRecords [POST]
  92. func AccessRecords(c *gin.Context) {
  93. var req *comm.AccessRecordsReq
  94. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  95. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  96. return
  97. }
  98. user := svc.GetUser(c)
  99. date := time.Now().Format("2006-01-02")
  100. cacheKey := fmt.Sprintf(md.UserAccessRecordsKey, user.Id, date, req.Index)
  101. get, err1 := cache.GetString(cacheKey)
  102. if err1 != nil || get == "" {
  103. recordsDb := implement.NewEggAccessRecordsDb(db.Db)
  104. exist, err := recordsDb.EggAccessRecordsExist(user.Id, date, req.Index)
  105. if err != nil {
  106. e.OutErr(c, e.ERR_DB_ORM, nil)
  107. }
  108. if exist {
  109. e.OutSuc(c, "success", nil)
  110. return
  111. }
  112. m := model.EggAccessRecords{
  113. Uid: user.Id,
  114. PageIndex: req.Index,
  115. Date: date,
  116. }
  117. _, err = recordsDb.EggAccessRecordsInsert(&m)
  118. if err != nil {
  119. e.OutErr(c, e.ERR_DB_ORM, nil)
  120. return
  121. }
  122. ttl := 3 * 60 * 60 // 记录保存三小时
  123. _, err = cache.SetEx(cacheKey, "1", ttl)
  124. if err != nil {
  125. fmt.Println("AccessRecordsRedis_ERR:::::", err.Error())
  126. utils.FilePutContents("AccessRecordsRedis_ERR", utils.SerializeStr(map[string]interface{}{
  127. "cacheKey": cacheKey,
  128. "err": err.Error(),
  129. }))
  130. }
  131. } else {
  132. e.OutSuc(c, "success", nil)
  133. return
  134. }
  135. e.OutSuc(c, "success", nil)
  136. }