report.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. package report
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_open_api/models/tables/company_report_permission"
  5. "hongze/hongze_open_api/utils"
  6. "time"
  7. )
  8. type ReportList struct {
  9. ResearchReportId int `json:"research_report_id" orm:"column(research_report_id)" description:"报告Id"`
  10. ResearchReportName string `json:"research_report_name" orm:"column(research_report_name)" description:"标题"`
  11. Periods int `json:"periods" description:"期数"`
  12. ResearchReportDate string `json:"research_report_date" description:"发布时间"`
  13. HttpUrl string `json:"http_url" description:"报告详情"`
  14. }
  15. type ReportListResp struct {
  16. List []*ReportList `description:"列表" json:"list"`
  17. Paging *utils.PagingItem `description:"分页数据" json:"paging"`
  18. }
  19. type ResearchReportInfo struct {
  20. ResearchReportInfo *ResearchReport `json:"research_report_info"`
  21. ResearchReportTypeList []*company_report_permission.ResearchReportTypeList `json:"research_report_type_list"`
  22. HasMenu int `json:"has_menu"`
  23. ResearchReportTypeContentList []*company_report_permission.ResearchReportTypeContent `description:"报告详情"`
  24. }
  25. //
  26. //// ResearchReport 研究报告表
  27. //type ResearchReport struct {
  28. // //ResearchReportID uint64 `gorm:"primaryKey;column:research_report_id;type:bigint(20) unsigned;not null" json:"-"` // 研究报告id
  29. // ResearchReportID uint64 `orm:"column(research_report_id)"json:"research_report_id";description:"报告Id"` // 研究报告id
  30. // ResearchReportName string `gorm:"index:research_report_name;column:research_report_name;type:varchar(128)" json:"research_report_name";description:"研究报告名称"` // 研究报告名称
  31. // ResearchReportTitle string `gorm:"index:research_report_title;column:research_report_title;type:varchar(128)" json:"research_report_title";description:"研究报告标题"` // 研究报告标题
  32. // ResearchReportImg string `gorm:"column:research_report_img;type:varchar(128)" json:"research_report_img";description:"报告缩略图URL"` // 报告缩略图URL
  33. // ResearchReportDate time.Time `gorm:"column:research_report_date;type:date;not null" description:"报告日期"` // 报告日期
  34. // Type string `gorm:"column:type;type:varchar(32);default:day" json:"type";description:"day 晨报 week 周报 twoweek双周报 month 月报"` // day 晨报 week 周报 twoweek双周报 month 月报
  35. // Author string `gorm:"column:author;type:varchar(100)" json:"author";description:"报告作者"` // 报告作者
  36. // ReportVariety string `gorm:"column:report_variety;type:varchar(30)" json:"report_variety";description:"研究报告的品种,双周报和月报有标识"` // 研究报告的品种,双周报和月报有标识
  37. // IsHasMenu int8 `gorm:"column:is_has_menu;type:tinyint(1);default:0" json:"is_has_menu";description:"报告Id"` // 报告是否含有目录
  38. // IsSendedMsg int8 `gorm:"column:is_sended_msg;type:tinyint(1);default:0" json:"is_sended_msg";description:"报告是否含有目录"` // 是否发送过模板消息
  39. // Periods int `gorm:"column:periods;type:int(8)" json:"periods";description:"期数"` // 期数
  40. // Status string `gorm:"column:status;type:varchar(20);not null" json:"status";description:"状态,draft:草稿"` // 状态,draft:草稿,
  41. // Enabled int8 `gorm:"index:enabled;column:enabled;type:tinyint(1);default:1" json:"enabled";description:"报告状态"` // 报告状态
  42. // CreatedTime time.Time `gorm:"index:created_time;column:created_time;type:datetime;default:CURRENT_TIMESTAMP" json:"created_time";description:"创建时间"` // 创建时间
  43. // LastUpdatedTime time.Time `gorm:"index:last_updated_time;column:last_updated_time;type:timestamp;not null;default:CURRENT_TIMESTAMP" json:"last_updated_time";description:"修改时间"`
  44. // Viewers int `gorm:"column:viewers;type:int(8);default:0" json:"viewers";description:"H5观看用户数"` // H5观看用户数
  45. //}
  46. type ResearchReport struct {
  47. //ResearchReportID uint64 `gorm:"primaryKey;column:research_report_id;type:bigint(20) unsigned;not null" json:"-"` // 研究报告id
  48. ResearchReportID uint64 `orm:"column(research_report_id)"json:"research_report_id";description:"报告Id"` // 研究报告id
  49. ResearchReportName string `gorm:"index:research_report_name;column:research_report_name;type:varchar(128)" json:"researchReportName";description:"研究报告名称"` // 研究报告名称
  50. ResearchReportTitle string `gorm:"index:research_report_title;column:research_report_title;type:varchar(128)" json:"researchReportTitle";description:"研究报告标题"` // 研究报告标题
  51. ResearchReportImg string `gorm:"column:research_report_img;type:varchar(128)" json:"researchReportImg";description:"报告缩略图URL"` // 报告缩略图URL
  52. ResearchReportDate time.Time `gorm:"column:research_report_date;type:date;not null" json:"researchReportDate";description:"报告日期"` // 报告日期
  53. Type string `gorm:"column:type;type:varchar(32);default:day" json:"type";description:"day 晨报 week 周报 twoweek双周报 month 月报"` // day 晨报 week 周报 twoweek双周报 month 月报
  54. Author string `gorm:"column:author;type:varchar(100)" json:"author";description:"报告作者"` // 报告作者
  55. ReportVariety string `gorm:"column:report_variety;type:varchar(30)" json:"reportVariety";description:"研究报告的品种,双周报和月报有标识"` // 研究报告的品种,双周报和月报有标识
  56. IsHasMenu int8 `gorm:"column:is_has_menu;type:tinyint(1);default:0" json:"isHasMenu";description:"报告Id"` // 报告是否含有目录
  57. IsSendedMsg int8 `gorm:"column:is_sended_msg;type:tinyint(1);default:0" json:"isSendedMsg";description:"报告是否含有目录"` // 是否发送过模板消息
  58. Periods int `gorm:"column:periods;type:int(8)" json:"periods";description:"期数"` // 期数
  59. Status string `gorm:"column:status;type:varchar(20);not null" json:"status";description:"状态,draft:草稿"` // 状态,draft:草稿,
  60. Enabled int8 `gorm:"index:enabled;column:enabled;type:tinyint(1);default:1" json:"enabled";description:"报告状态"` // 报告状态
  61. CreatedTime time.Time `gorm:"index:created_time;column:created_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createdTime";description:"创建时间"` // 创建时间
  62. LastUpdatedTime time.Time `gorm:"index:last_updated_time;column:last_updated_time;type:timestamp;not null;default:CURRENT_TIMESTAMP" json:"lastUpdatedTime";description:"修改时间"`
  63. Viewers int `gorm:"column:viewers;type:int(8);default:0" json:"viewers";description:"H5观看用户数"` // H5观看用户数
  64. }
  65. type ResearchReportTypeContent struct {
  66. ResearchReportTypeTitle string
  67. ResearchReportTypeContentId int `json:"research_report_type_content_id" description:"研究报告内容id"`
  68. ResearchReportTypeId int `json:"research_report_id" description:"报告id"`
  69. Sort int `json:"sort" description:"排序"`
  70. ContentType string `json:"content_type" description:"内容分类类型"`
  71. Content string `json:"content" description:"内容"`
  72. ImgUrl string `json:"img_url" description:"图片路径"`
  73. CreatedTime time.Time `json:"created_time" description:"创建时间"`
  74. LastUpdatedTime time.Time `json:"last_updated_time" description:"最近一次更新时间"`
  75. }
  76. func GetReportListCount(condition string, pars []interface{}) (count int, err error) {
  77. o := orm.NewOrm()
  78. sql := `SELECT COUNT(1) AS count FROM research_report WHERE 1=1 `
  79. if condition != "" {
  80. sql += condition
  81. }
  82. err = o.Raw(sql, pars).QueryRow(&count)
  83. return
  84. }
  85. func GetReportList(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  86. o := orm.NewOrm()
  87. //产品权限
  88. sql := `SELECT * FROM research_report WHERE 1=1`
  89. if condition != "" {
  90. sql += condition
  91. }
  92. sql += `ORDER BY periods DESC LIMIT ?,?`
  93. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  94. return
  95. }
  96. //GetResearchReportInfo 获取报告详情
  97. func GetResearchReportInfo(researchReportId, userId int) (result ResearchReportInfo, hasPermission bool, err error) {
  98. //获取报告详情
  99. reportInfo, err := GetByResearchReportId(researchReportId)
  100. if err != nil {
  101. return
  102. }
  103. reportType := reportInfo.Type
  104. //这些个报告需要做权限校验
  105. if utils.InArray(reportInfo.Type, []string{"month", "two_week", "other"}) {
  106. list, tmpErr := company_report_permission.GetReportVarietyList(userId, reportType)
  107. if tmpErr != nil {
  108. err = tmpErr
  109. return
  110. }
  111. for _, v := range list {
  112. if reportInfo.ResearchReportID == v.ReportChapterTypeId {
  113. hasPermission = true
  114. break
  115. }
  116. }
  117. if !hasPermission {
  118. return
  119. }
  120. } else {
  121. hasPermission = true
  122. }
  123. researchReportTypeList := make([]*company_report_permission.ResearchReportTypeList, 0)
  124. tmpResearchReportTypeList, err := company_report_permission.GetResearchReportType(reportInfo.ResearchReportID, userId, reportInfo.Type)
  125. if err != nil {
  126. return
  127. }
  128. reportDate := reportInfo.ResearchReportDate
  129. for _, v := range tmpResearchReportTypeList {
  130. if reportDate.Before(v.PauseStartTime) || reportDate.After(v.PauseEndTime) {
  131. researchReportTypeList = append(researchReportTypeList, v)
  132. }
  133. }
  134. result = ResearchReportInfo{
  135. ResearchReportInfo: reportInfo,
  136. ResearchReportTypeList: researchReportTypeList,
  137. HasMenu: 1,
  138. }
  139. if len(researchReportTypeList) <= 0 {
  140. } else if len(researchReportTypeList) == 1 {
  141. //只有一个章节,即没有目录的时候,需要直接返回章节详情
  142. result.HasMenu = 0
  143. researchReportTypeContent, tmpErr := company_report_permission.GetResearchReportTypeContentList(researchReportTypeList[0].ResearchReportTypeId)
  144. if tmpErr != nil {
  145. return
  146. }
  147. result.ResearchReportTypeContentList = researchReportTypeContent
  148. }
  149. return
  150. }
  151. // GetPermissionNameByReportId
  152. func GetByResearchReportId(researchReportid int) (item *ResearchReport, err error) {
  153. sql := `SELECT * FROM research_report WHERE research_report_id = ?`
  154. o := orm.NewOrm()
  155. err = o.Raw(sql, researchReportid).QueryRow(&item)
  156. return
  157. }
  158. type ResearchReportTypeContentInfo struct {
  159. ResearchReportTypeInfo *company_report_permission.ResearchReportTypeInfo `json:"research_report_type_info"`
  160. Add int `json:"add"`
  161. ResearchReportTypeContentList []*company_report_permission.ResearchReportTypeContent `description:"报告详情" json:"research_report_type_content_list"`
  162. ResearchReportTypeList []*company_report_permission.ResearchReportTypeList `json:"research_report_type_list"`
  163. }
  164. // GetResearchReportTypeContentInfo 获取报告章节详情
  165. func GetResearchReportTypeContentInfo(researchReportTypeId, userId uint64) (result ResearchReportTypeContentInfo, hasPermission bool, err error) {
  166. //获取章节详情
  167. researchReportTypeContentList, err := company_report_permission.GetResearchReportTypeContentList(researchReportTypeId)
  168. if err != nil {
  169. return
  170. }
  171. researchReportTypeInfo, err := company_report_permission.GetResearchReportTypeInfo(researchReportTypeId)
  172. if err != nil {
  173. return
  174. }
  175. //获取报告详情
  176. reportInfo, err := GetByResearchReportId(int(researchReportTypeInfo.ResearchReportID))
  177. if err != nil {
  178. return
  179. }
  180. reportType := reportInfo.Type
  181. researchReportTypeInfo.Type = reportInfo.Type
  182. //这些个报告需要做权限校验
  183. if utils.InArray(reportInfo.Type, []string{"week", "month", "two_week", "other"}) {
  184. list, tmpErr := company_report_permission.GetReportVarietyList(int(userId), reportType)
  185. if tmpErr != nil {
  186. err = tmpErr
  187. return
  188. }
  189. if reportInfo.Type == "week" {
  190. //周报校验章节是否在权限内
  191. for _, v := range list {
  192. if researchReportTypeInfo.ReportChapterTypeId == v.ReportChapterTypeId {
  193. hasPermission = true
  194. break
  195. }
  196. }
  197. } else {
  198. //双周报和月报校验 类型是否在权限内
  199. for _, v := range list {
  200. if reportInfo.ResearchReportID == v.ReportChapterTypeId {
  201. hasPermission = true
  202. break
  203. }
  204. }
  205. }
  206. if !hasPermission {
  207. return
  208. }
  209. } else {
  210. hasPermission = true
  211. }
  212. add := 1
  213. if len(researchReportTypeContentList) > 0 {
  214. add = 0
  215. }
  216. result = ResearchReportTypeContentInfo{
  217. ResearchReportTypeContentList: researchReportTypeContentList,
  218. ResearchReportTypeInfo: researchReportTypeInfo,
  219. Add: add,
  220. }
  221. return
  222. }