custom_query.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package company_report_permission
  2. import (
  3. "fmt"
  4. "rdluck_tools/orm"
  5. "strings"
  6. "time"
  7. )
  8. type ReportChapterTypeIdList struct {
  9. ReportChapterTypeId uint64
  10. }
  11. type ResearchReportTypeInfo struct {
  12. ResearchReportTypeTitle string `json:"research_report_type_title" description:"研究报告标题"`
  13. BannerUrl string `json:"banner_url" description:"banner url"`
  14. ReportChapterTypeName string `json:"report_chapter_type_name" description:"章节名称"`
  15. ResearchReportID uint64 `orm:"column(research_report_id)";json:"research_report_id" description:"报告id"`
  16. ResearchReportTypeID uint64 `orm:"column(research_report_type_id)";json:"research_report_type_id" description:"研究报告id"`
  17. TypeID int `orm:"column(type_id)";json:"type_id" description:"分类id"`
  18. ReportChapterTypeId uint64 `json:"report_chapter_type_id" description:"章节名称"`
  19. }
  20. type ResearchReportTypeList struct {
  21. ResearchReportTypeId uint64 ` description:"章节ID"`
  22. ResearchReportId uint64 ` description:"研究报告id"`
  23. ResearchReportTypeTitle string `description:"研究报告标题"`
  24. TypeId int `description:"分类id"`
  25. Edit int8 `description:"是否编辑过"`
  26. Trend string `description:"趋势观点"`
  27. ReportChapterTypeKey string `description:"章节key"`
  28. ReportChapterTypeThumb string `description:"H5展示的图片"`
  29. BannerUrl string `description:"banner显示图片"`
  30. ReportChapterTypeName string `description:"报告章节类型名称"`
  31. Sort int `description:"排序字段"`
  32. EditImgUrl string `description:"管理后台编辑时选用的图"`
  33. PauseStartTime time.Time `description:"暂停开始日期"`
  34. PauseEndTime time.Time `description:"暂停结束日期"`
  35. LastUpdatedTime time.Time `description:"最后更新时间"`
  36. HttpUrl string `json:"http_url",description:"报告详情"`
  37. }
  38. //GetResearchReportType 获取研究报告的章节详情
  39. func GetResearchReportType(researchReportId uint64, userId int, reportType string) (list []*ResearchReportTypeList, err error) {
  40. var condition string
  41. //whereVals := make([]interface{}, 0)
  42. //如果是周报,并且是H5页面
  43. if "week" == reportType && userId > 0 {
  44. condition += ` and rrt.edit=1 `
  45. reportChapterTypeList, tmpErr := GetReportVarietyList(userId, reportType)
  46. if tmpErr != nil {
  47. err = tmpErr
  48. return
  49. }
  50. if len(reportChapterTypeList) > 0 {
  51. reportChapterTypeIdList := make([]string, 0)
  52. for _, v := range reportChapterTypeList {
  53. reportChapterTypeIdList = append(reportChapterTypeIdList, fmt.Sprint(v.ReportChapterTypeId))
  54. }
  55. condition += ` and rct.report_chapter_type_id in (` + strings.Join(reportChapterTypeIdList, ",") + `) `
  56. //whereVals = append(whereVals, strings.Join(reportChapterTypeIdList, ","))
  57. }
  58. }
  59. if strings.Contains("day,week", reportType) {
  60. condition += ` and rct.is_show=1 `
  61. }
  62. sql := `select
  63. rrt.research_report_type_id,
  64. rrt.research_report_id,
  65. rrt.research_report_type_title,
  66. rrt.type_id,
  67. rrt.edit,
  68. rrt.trend,
  69. rct.report_chapter_type_key,
  70. rct.report_chapter_type_thumb,
  71. rct.banner_url,
  72. rct.report_chapter_type_name,
  73. rct.sort,
  74. rct.edit_img_url,
  75. rct.pause_start_time,
  76. rct.pause_end_time,
  77. rrt.last_updated_time
  78. from research_report_type rrt
  79. left JOIN report_chapter_type rct on rct.report_chapter_type_id = rrt.type_id
  80. where rrt.research_report_id = ? `
  81. sql += condition
  82. sql += ` order by rct.sort,rrt.research_report_type_id `
  83. o := orm.NewOrm()
  84. _, err = o.Raw(sql, researchReportId).QueryRows(&list)
  85. return
  86. }
  87. type PermissionName struct {
  88. ChartPermissionName string
  89. ResearchType string
  90. }
  91. //权限
  92. // GetReportVarietyList
  93. func GetReportVarietyList(userId int, reportType string) (list []*ReportChapterTypeIdList, err error) {
  94. o := orm.NewOrm()
  95. var condition string
  96. //whereVals := make([]interface{}, 0)
  97. if reportType != "" {
  98. condition += ` and cpcm.research_type = '` + reportType + `' `
  99. //whereVals = append(whereVals, reportType)
  100. }
  101. sql := ` SELECT cpcm.report_chapter_type_id FROM company_report_permission crp
  102. INNER JOIN chart_permission_chapter_mapping cpcm ON crp.chart_permission_id = cpcm.chart_permission_id
  103. INNER JOIN wx_user wu ON wu.company_id = crp.company_id
  104. WHERE wu.user_id = ? `
  105. sql += condition
  106. sql += ` GROUP BY cpcm.report_chapter_type_id `
  107. _, err = o.Raw(sql, userId).QueryRows(&list)
  108. return
  109. }
  110. type ResearchReportTypeContent struct {
  111. ResearchReportTypeTitle string
  112. ResearchReportTypeContentId int `json:"research_report_type_content_id" description:"研究报告内容id"`
  113. ResearchReportTypeId int `json:"research_report_id" description:"报告id"`
  114. Sort int `json:"sort" description:"排序"`
  115. ContentType string `json:"content_type" description:"内容分类类型"`
  116. Content string `json:"content" description:"内容"`
  117. ImgUrl string `json:"img_url" description:"图片路径"`
  118. CreatedTime time.Time `json:"created_time" description:"创建时间"`
  119. LastUpdatedTime time.Time `json:"last_updated_time" description:"最近一次更新时间"`
  120. }
  121. // GetResearchReportTypeContentList 获取研究报告章节详情
  122. func GetResearchReportTypeContentList(researchReportTypeId uint64) (items []*ResearchReportTypeContent, err error) {
  123. o := orm.NewOrm()
  124. sql := `select rrt.research_report_type_title,rrtc.*,rrt.research_report_type_id
  125. from research_report_type rrt
  126. inner join research_report_type_content rrtc on rrtc.research_report_type_id = rrt.research_report_type_id
  127. where rrt.research_report_type_id = ? `
  128. _, err = o.Raw(sql, researchReportTypeId).QueryRows(&items)
  129. return
  130. }
  131. // GetResearchReportTypeInfo 获取研究报告类型详情
  132. func GetResearchReportTypeInfo(researchReportTypeId uint64) (item *ResearchReportTypeInfo, err error) {
  133. sql := ` select rrt.research_report_type_title,rct.banner_url,rct.report_chapter_type_name,rrt.research_report_id,rrt.research_report_type_id,rrt.type_id,rct.report_chapter_type_name,rct.report_chapter_type_id
  134. from research_report_type rrt
  135. left join report_chapter_type rct on rct.report_chapter_type_id = rrt.type_id
  136. where rrt.research_report_type_id =? limit 1`
  137. o := orm.NewOrm()
  138. err = o.Raw(sql, researchReportTypeId).QueryRow(&item)
  139. return
  140. }