蛋蛋星球-客户端
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.0 KiB

1 month ago
1 month ago
1 month ago
1 week ago
1 month ago
1 month ago
1 month ago
1 week 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 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 month ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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/cache"
  10. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  11. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  12. enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  13. "errors"
  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, date, req.Index)
  101. if !cache.Exists(cacheKey) {
  102. ttl := 24 * 60 * 60 // 记录保存24小时
  103. _, err := cache.SetEx(cacheKey, nil, ttl)
  104. if err != nil {
  105. e.OutErr(c, e.ERR, err.Error())
  106. return
  107. }
  108. }
  109. get, err1 := cache.GetBit(cacheKey, user.Id)
  110. if err1 != nil || get == 0 {
  111. recordsDb := implement.NewEggAccessRecordsDb(db.Db)
  112. exist, err := recordsDb.EggAccessRecordsExist(user.Id, date, req.Index)
  113. if err != nil {
  114. e.OutErr(c, e.ERR_DB_ORM, nil)
  115. }
  116. if !exist {
  117. m := model.EggAccessRecords{
  118. Uid: user.Id,
  119. PageIndex: req.Index,
  120. Date: date,
  121. }
  122. _, err = recordsDb.EggAccessRecordsInsert(&m)
  123. if err != nil {
  124. e.OutErr(c, e.ERR_DB_ORM, nil)
  125. return
  126. }
  127. }
  128. _, err = cache.SetBit(cacheKey, user.Id, 1)
  129. if err != nil {
  130. e.OutErr(c, e.ERR, err.Error())
  131. return
  132. }
  133. } else {
  134. e.OutErr(c, e.ERR, errors.New("无效的重复请求").Error())
  135. return
  136. }
  137. e.OutSuc(c, "success", nil)
  138. }