chart_permission.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. package controllers
  2. import (
  3. "hongze/hongze_cygx/models"
  4. "hongze/hongze_cygx/services"
  5. "hongze/hongze_cygx/utils"
  6. )
  7. // 品种
  8. type ChartPermissionController struct {
  9. BaseCommonController
  10. }
  11. type ChartPermissionAuthController struct {
  12. BaseAuthController
  13. }
  14. // @Title 获取所有品种
  15. // @Description 获取用户详情接口
  16. // @Success 200 {object} models.ChartPermissionResp
  17. // @router /all [get]
  18. func (this *ChartPermissionAuthController) Detail() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. user := this.User
  25. if user == nil {
  26. br.Msg = "请重新登录"
  27. br.Ret = 408
  28. return
  29. }
  30. var condition string
  31. var userType int
  32. if user.CompanyId > 1 {
  33. total, err := models.GetCountCompanyDetailByIdGroup(user.CompanyId)
  34. if err != nil {
  35. br.Msg = "获取失败"
  36. br.ErrMsg = "获取失败,Err:" + err.Error()
  37. return
  38. }
  39. if total == 0 {
  40. userType = 0
  41. } else {
  42. companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
  43. if err != nil {
  44. br.Msg = "获取信息失败!"
  45. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  46. return
  47. }
  48. if companyDetail.Status == "永续" {
  49. userType = 1
  50. }
  51. }
  52. }
  53. if userType == 1 {
  54. condition += ` AND permission_name != '研选'`
  55. }
  56. condition += ` AND permission_name != '医药'`
  57. list, err := models.GetChartPermissionAll(condition)
  58. if err != nil {
  59. br.Msg = "获取信息失败"
  60. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  61. return
  62. }
  63. resp := new(models.ChartPermissionResp)
  64. for k, v := range list {
  65. if userType == 1 {
  66. if v.PermissionName != "研选" {
  67. resp.List = append(resp.List, v)
  68. }
  69. } else {
  70. resp.List = append(resp.List, v)
  71. }
  72. if services.GetShowSustainable() && v.PermissionName == "研选" {
  73. resp.List[k].IsShowSustainable = true
  74. }
  75. }
  76. resp.List = list
  77. br.Ret = 200
  78. br.Success = true
  79. br.Msg = "获取成功"
  80. br.Data = resp
  81. }
  82. // @Title 获取报告所有品种
  83. // @Description 获取报告所有品种接口
  84. // @Success 200 {object} models.ChartPermissionResp
  85. // @router /reportall [get]
  86. func (this *ChartPermissionAuthController) ReportDetail() {
  87. br := new(models.BaseResponse).Init()
  88. defer func() {
  89. this.Data["json"] = br
  90. this.ServeJSON()
  91. }()
  92. user := this.User
  93. if user == nil {
  94. br.Msg = "请重新登录"
  95. br.Ret = 408
  96. return
  97. }
  98. var condition string
  99. var userType int
  100. if user.CompanyId > 1 {
  101. total, err := models.GetCountCompanyDetailByIdGroup(user.CompanyId)
  102. if err != nil {
  103. br.Msg = "获取失败"
  104. br.ErrMsg = "获取失败,Err:" + err.Error()
  105. return
  106. }
  107. if total == 0 {
  108. userType = 0
  109. } else {
  110. companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
  111. if err != nil {
  112. br.Msg = "获取信息失败!"
  113. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  114. return
  115. }
  116. if companyDetail.Status == "永续" {
  117. userType = 1
  118. }
  119. }
  120. }
  121. if userType == 1 {
  122. condition += ` AND permission_name != '买方研选'`
  123. }
  124. list, err := models.GetChartPermissionReportAll(condition)
  125. if err != nil {
  126. br.Msg = "获取信息失败"
  127. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  128. return
  129. }
  130. resp := new(models.ChartPermissionResp)
  131. for k, v := range list {
  132. if userType == 1 {
  133. if v.PermissionName != "研选" {
  134. resp.List = append(resp.List, v)
  135. }
  136. } else {
  137. resp.List = append(resp.List, v)
  138. }
  139. if services.GetShowSustainable() && v.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  140. resp.List[k].IsShowSustainable = true
  141. }
  142. }
  143. br.Ret = 200
  144. br.Success = true
  145. br.Msg = "获取成功"
  146. br.Data = resp
  147. }
  148. // @Title 获取策略下的所有分类
  149. // @Description 获取策略下的所有分类接口
  150. // @Param ChartPermissionId query int false "行业id"
  151. // @Success 200 {object} models.ReportMappingResp
  152. // @router /strategyAll [get]
  153. func (this *ChartPermissionAuthController) StrategyDetail() {
  154. br := new(models.BaseResponse).Init()
  155. defer func() {
  156. this.Data["json"] = br
  157. this.ServeJSON()
  158. }()
  159. user := this.User
  160. if user == nil {
  161. br.Msg = "请重新登录"
  162. br.Ret = 408
  163. return
  164. }
  165. //默认给策略的ID
  166. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  167. if chartPermissionId == 0 {
  168. chartPermissionId = utils.CE_LUE_ID
  169. }
  170. uid := user.UserId
  171. list, err := models.GetReportMappingStrategyHomeAll(chartPermissionId)
  172. if err != nil {
  173. br.Msg = "获取信息失败"
  174. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  175. return
  176. }
  177. for k, v := range list {
  178. count, err := models.GetUserIsReadThisNewCategoryArticleCount(v.CategoryId, uid)
  179. if err != nil && err.Error() != utils.ErrNoRow() {
  180. br.Msg = "获取信息失败"
  181. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  182. return
  183. }
  184. Newdetail, err := models.GetNewArticleByCategoryId(v.CategoryId)
  185. if err != nil {
  186. br.Msg = "获取信息失败"
  187. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  188. return
  189. }
  190. if count == 0 && user.CreatedTime.Before(utils.StrTimeToTime(Newdetail.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(Newdetail.PublishDate)) {
  191. list[k].IsRed = true
  192. }
  193. }
  194. cf, err := models.GetConfigByCode(utils.CYGX_TACTICS_TIME_LINE_STATUS)
  195. if err != nil {
  196. br.Msg = "获取失败"
  197. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  198. return
  199. }
  200. resp := new(models.ReportMappingHomeResp)
  201. if cf.ConfigValue == "1" || user.CompanyId == utils.HZ_COMPANY_ID {
  202. item := new(models.ReportMappingHome)
  203. item.CategoryId = utils.TIME_LINE_ID
  204. item.SubCategoryName = utils.TIME_LINE_NAME
  205. item.MatchTypeName = utils.TIME_LINE_NAME
  206. resp.List = append(resp.List, item)
  207. }
  208. for _, v := range list {
  209. resp.List = append(resp.List, v)
  210. }
  211. br.Ret = 200
  212. br.Success = true
  213. br.Msg = "获取成功"
  214. br.Data = resp
  215. }
  216. // @Title 获取所有品种(无需token)
  217. // @Description 获取所有品种(无需token)
  218. // @Success 200 {object} models.ChartPermissionResp
  219. // @router /allPublic [get]
  220. func (this *ChartPermissionController) DetailPublic() {
  221. br := new(models.BaseResponse).Init()
  222. defer func() {
  223. this.Data["json"] = br
  224. this.ServeJSON()
  225. }()
  226. var condition string
  227. list, err := models.GetChartPermissionAll(condition)
  228. if err != nil {
  229. br.Msg = "获取信息失败"
  230. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  231. return
  232. }
  233. resp := new(models.ChartPermissionResp)
  234. for k, v := range list {
  235. resp.List = append(resp.List, v)
  236. if services.GetShowSustainable() && v.PermissionName == "研选" {
  237. resp.List[k].IsShowSustainable = true
  238. }
  239. }
  240. resp.List = list
  241. br.Ret = 200
  242. br.Success = true
  243. br.Msg = "获取成功"
  244. br.Data = resp
  245. }
  246. // @Title 获取报告所有品种7.0版本
  247. // @Description 获取报告所有品种接口7.0版本
  248. // @Success 200 {object} models.ChartPermissionResp
  249. // @router /reportallV7 [get]
  250. func (this *ChartPermissionAuthController) ReportDetailV7() {
  251. br := new(models.BaseResponse).Init()
  252. defer func() {
  253. this.Data["json"] = br
  254. this.ServeJSON()
  255. }()
  256. user := this.User
  257. if user == nil {
  258. br.Msg = "请重新登录"
  259. br.Ret = 408
  260. return
  261. }
  262. var condition string
  263. var userType int
  264. if user.CompanyId > 1 {
  265. total, err := models.GetCountCompanyDetailByIdGroup(user.CompanyId)
  266. if err != nil {
  267. br.Msg = "获取失败"
  268. br.ErrMsg = "获取失败,Err:" + err.Error()
  269. return
  270. }
  271. if total == 0 {
  272. userType = 0
  273. } else {
  274. companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
  275. if err != nil {
  276. br.Msg = "获取信息失败!"
  277. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  278. return
  279. }
  280. if companyDetail.Status == "永续" {
  281. userType = 1
  282. }
  283. }
  284. }
  285. condition += ` AND permission_name != '买方研选'`
  286. list, err := models.GetChartPermissionReportAll(condition)
  287. if err != nil {
  288. br.Msg = "获取信息失败"
  289. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  290. return
  291. }
  292. resp := new(models.ChartPermissionResp)
  293. for k, v := range list {
  294. if userType == 1 {
  295. if v.PermissionName != "研选" {
  296. resp.List = append(resp.List, v)
  297. }
  298. } else {
  299. resp.List = append(resp.List, v)
  300. }
  301. if services.GetShowSustainable() && v.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  302. resp.List[k].IsShowSustainable = true
  303. }
  304. }
  305. item := new(models.ChartPermission)
  306. item.PermissionName = utils.GU_SHOU_NAME
  307. item.ChartPermissionId = utils.GU_SHOU_ID
  308. resp.List = append(resp.List, item)
  309. br.Ret = 200
  310. br.Success = true
  311. br.Msg = "获取成功"
  312. br.Data = resp
  313. }