product.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package controllers
  2. import (
  3. "eta/eta_mini_crm_ht/models"
  4. "eta/eta_mini_crm_ht/models/response"
  5. "eta/eta_mini_crm_ht/services"
  6. "eta/eta_mini_crm_ht/utils"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. "strconv"
  9. "strings"
  10. "sync"
  11. )
  12. type ProductController struct {
  13. BaseAuthController
  14. }
  15. // UnSetProductList
  16. // @Title 未设置的产品列表
  17. // @Description 未设置的产品列表
  18. // @Param PageSize query int true "每页数据条数"
  19. // @Param CurrentIndex query int true "当前页页码,从1开始"
  20. // @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
  21. // @Param KeyWord query string true "报告标题/创建人"
  22. // @Param SortType query string true "排序方式"
  23. // @Success 200 {object} models.ReportAuthorResp
  24. // @router /unSetProductList [get]
  25. func (this *ProductController) UnSetProductList() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. pageSize, _ := this.GetInt("PageSize")
  32. currentIndex, _ := this.GetInt("CurrentIndex")
  33. sortType := this.GetString("SortType")
  34. ProductType := this.GetString("ProductType")
  35. permissionIds := this.GetString("PermissionIds")
  36. KeyWord := this.GetString("KeyWord")
  37. var condition string
  38. var pars []interface{}
  39. if pageSize <= 0 {
  40. pageSize = utils.PageSize20
  41. }
  42. if currentIndex <= 0 {
  43. currentIndex = 1
  44. }
  45. if ProductType == "" {
  46. br.Msg = "产品类型不能为空"
  47. br.ErrMsg = "获取未设置产品列表失败,Err:产品类型为空"
  48. return
  49. }
  50. if KeyWord != "" {
  51. switch ProductType {
  52. case "report":
  53. condition += " AND title like '%?%'"
  54. case "media":
  55. condition += " AND media_name like '%?%'"
  56. }
  57. pars = append(pars, KeyWord)
  58. }
  59. sortCondition := " ORDER BY published_time "
  60. if sortType == "" {
  61. sortType = "DESC"
  62. }
  63. sortCondition = sortCondition + sortType
  64. var permissionIdsList []int
  65. if permissionIds != "" {
  66. permissionStr := strings.Split(permissionIds, ",")
  67. for _, permissionItem := range permissionStr {
  68. permissionId, _ := strconv.Atoi(permissionItem)
  69. permissionIdsList = append(permissionIdsList, permissionId)
  70. }
  71. }
  72. total, ids, err := services.GetUnsetProductCountByCondition(ProductType, permissionIdsList, condition, pars)
  73. if err != nil {
  74. br.Msg = "获取未设置产品列表失败"
  75. br.ErrMsg = "获取未设置产品列表失败,Err:" + err.Error()
  76. return
  77. }
  78. var list []*services.ProductView
  79. if len(ids) > 0 {
  80. startSize := utils.StartIndex(currentIndex, pageSize)
  81. list, err = services.GetUnsetProductByCondition(ProductType, ids, sortCondition, startSize, pageSize)
  82. if err != nil {
  83. br.Msg = "获取未设置产品列表失败"
  84. br.ErrMsg = "获取未设置产品列表失败,Err:" + err.Error()
  85. return
  86. }
  87. }
  88. var wg sync.WaitGroup
  89. wg.Add(len(list))
  90. for _, product := range list {
  91. go func(product *services.ProductView) {
  92. defer wg.Done()
  93. switch product.ProductType {
  94. case "report":
  95. product.RiskLevel = product.GetRiskLevel("report", product.SourceId)
  96. product.ProductType = "报告"
  97. case "video":
  98. product.RiskLevel = product.GetRiskLevel("media", product.SourceId)
  99. product.ProductType = "视频"
  100. case "audio":
  101. product.RiskLevel = product.GetRiskLevel("media", product.SourceId)
  102. product.ProductType = "音频"
  103. }
  104. }(product)
  105. }
  106. wg.Wait()
  107. page := paging.GetPaging(currentIndex, pageSize, total)
  108. resp := new(response.ProductListResp)
  109. resp.List = list
  110. resp.Paging = page
  111. br.Ret = 200
  112. br.Success = true
  113. br.Data = resp
  114. br.Msg = "获取成功"
  115. }
  116. //
  117. //// UploadFile @Title 上传图片
  118. //// @Description 上传视频
  119. //// @Param File query file true "文件"
  120. //// @Success 200 {object} models.ReportAuthorResp
  121. //// @router /uploadFile [post]
  122. //func (this *VideoController) UploadFile() {
  123. // br := new(models.BaseResponse).Init()
  124. // defer func() {
  125. // this.Data["json"] = br
  126. // this.ServeJSON()
  127. // }()
  128. // f, h, err := this.GetFile("File")
  129. // if err != nil {
  130. // br.Msg = "获取资源信息失败"
  131. // br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  132. // return
  133. // }
  134. // defer f.Close()
  135. // size, err := strconv.Atoi(utils.UPLOAD_IMG_SIZE)
  136. // if err != nil {
  137. // size = 100
  138. // }
  139. // if h.Size > 1024*1024*int64(size) {
  140. // br.Msg = fmt.Sprintf("图片大小不能超过%dK", size)
  141. // br.ErrMsg = "图片上传失败,Err:" + err.Error()
  142. // return
  143. // }
  144. // ext := path.Ext(h.Filename)
  145. // //if ext != ".mp3" {
  146. // // br.Msg = "音频格式不正确"
  147. // // br.ErrMsg = "音频上传失败,Err:" + err.Error()
  148. // // return
  149. // //}
  150. // dateDir := time.Now().Format("20060102")
  151. // uploadDir := utils.STATIC_DIR + "ht/audio" + dateDir
  152. // err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  153. // if err != nil {
  154. // br.Msg = "存储目录创建失败"
  155. // br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  156. // return
  157. // }
  158. // randStr := utils.GetRandStringNoSpecialChar(28)
  159. // fileName := randStr + ext
  160. // fpath := uploadDir + "/" + fileName
  161. // err = this.SaveToFile("File", fpath)
  162. // if err != nil {
  163. // br.Msg = "图片上传失败"
  164. // br.ErrMsg = "图片上传失败,Err:" + err.Error()
  165. // return
  166. // }
  167. // audioUploadDir := utils.RESOURCE_DIR + "img/"
  168. // savePdfToOssPath := audioUploadDir + time.Now().Format("200601/20060102/")
  169. // audioName := utils.GetRandStringNoSpecialChar(28)
  170. // savePdfToOssPath += audioName + ext
  171. //
  172. // defer func() {
  173. // err = os.Remove(fpath)
  174. // fmt.Sprintf("删除文件失败:%v", err)
  175. // }()
  176. // ossClient := services.NewOssClient()
  177. // if ossClient == nil {
  178. // br.Msg = "图片上传失败"
  179. // br.ErrMsg = "初始化OSS服务失败"
  180. // return
  181. // }
  182. // mp3Url, err := ossClient.UploadFile("", fpath, savePdfToOssPath)
  183. // if err != nil {
  184. // br.Msg = "图片上传失败"
  185. // br.ErrMsg = "图片上传失败,Err:" + err.Error()
  186. // return
  187. // }
  188. // base := path.Base(h.Filename)
  189. // resp := new(response.MediaUploadResp)
  190. // resp.Url = mp3Url
  191. // resp.FileName = base
  192. // br.Data = resp
  193. // br.Msg = "上传成功"
  194. // br.Ret = 200
  195. // br.Success = true
  196. //}