english_report.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. package models
  2. import (
  3. "eta/eta_hub/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "strings"
  8. "time"
  9. )
  10. type EnglishReport struct {
  11. Id int `orm:"column(id)" description:"报告Id"`
  12. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  13. ClassifyIdFirst int `description:"一级分类id"`
  14. ClassifyNameFirst string `description:"一级分类名称"`
  15. ClassifyIdSecond int `description:"二级分类id"`
  16. ClassifyNameSecond string `description:"二级分类名称"`
  17. Title string `description:"标题"`
  18. Abstract string `description:"摘要"`
  19. Author string `description:"作者"`
  20. Frequency string `description:"频度"`
  21. CreateTime time.Time `description:"创建时间"`
  22. ModifyTime time.Time `description:"修改时间"`
  23. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  24. PublishTime time.Time `description:"发布时间"`
  25. PrePublishTime time.Time `description:"预发布时间"`
  26. Stage int `description:"期数"`
  27. Content string `description:"内容"`
  28. VideoUrl string `description:"音频文件URL"`
  29. VideoName string `description:"音频文件名称"`
  30. VideoPlaySeconds string `description:"音频播放时长"`
  31. VideoSize string `description:"音频文件大小,单位M"`
  32. ContentSub string `description:"内容前两个章节"`
  33. ReportCode string `description:"报告唯一编码"`
  34. Pv int `description:"Pv"`
  35. PvEmail int `description:"邮箱PV"`
  36. EmailState int `description:"群发邮件状态: 0-未发送; 1-已发送"`
  37. Overview string `description:"英文概述部分"`
  38. KeyTakeaways string `description:"关键点"`
  39. FromReportId int `description:"继承的报告ID(英文策略报告ID)"`
  40. AdminId int `description:"创建者账号"`
  41. AdminRealName string `description:"创建者姓名"`
  42. ApproveTime time.Time `description:"审批时间"`
  43. ApproveId int `description:"审批ID"`
  44. }
  45. func (m *EnglishReport) Update(cols []string) (err error) {
  46. o := orm.NewOrmUsingDB("rddp")
  47. _, err = o.Update(m, cols...)
  48. return
  49. }
  50. func (m *EnglishReport) GetItemById(id int) (item *EnglishReport, err error) {
  51. o := orm.NewOrmUsingDB("rddp")
  52. sql := `SELECT * FROM english_report WHERE id = ? LIMIT 1`
  53. err = o.Raw(sql, id).QueryRow(&item)
  54. return
  55. }
  56. func (m *EnglishReport) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  57. o := orm.NewOrmUsingDB("rddp")
  58. sql := fmt.Sprintf(`SELECT COUNT(1) FROM english_report WHERE 1=1 %s`, condition)
  59. err = o.Raw(sql, pars).QueryRow(&count)
  60. return
  61. }
  62. func (m *EnglishReport) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EnglishReport, err error) {
  63. o := orm.NewOrmUsingDB("rddp")
  64. fields := strings.Join(fieldArr, ",")
  65. if len(fieldArr) == 0 {
  66. fields = `*`
  67. }
  68. order := `ORDER BY create_time DESC`
  69. if orderRule != "" {
  70. order = ` ORDER BY ` + orderRule
  71. }
  72. sql := fmt.Sprintf(`SELECT %s FROM english_report WHERE 1=1 %s %s`, fields, condition, order)
  73. _, err = o.Raw(sql, pars).QueryRows(&items)
  74. return
  75. }
  76. func (m *EnglishReport) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*EnglishReport, err error) {
  77. o := orm.NewOrmUsingDB("rddp")
  78. fields := strings.Join(fieldArr, ",")
  79. if len(fieldArr) == 0 {
  80. fields = `*`
  81. }
  82. order := `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC`
  83. if orderRule != "" {
  84. order = ` ORDER BY ` + orderRule
  85. }
  86. sql := fmt.Sprintf(`SELECT %s FROM english_report WHERE 1=1 %s %s LIMIT ?,?`, fields, condition, order)
  87. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  88. return
  89. }
  90. type EnglishReportItem struct {
  91. Id int `description:"报告Id"`
  92. ReportCode string `description:"报告唯一编码"`
  93. ClassifyIdFirst int `description:"一级分类id"`
  94. ClassifyNameFirst string `description:"一级分类名称"`
  95. ClassifyIdSecond int `description:"二级分类id"`
  96. ClassifyNameSecond string `description:"二级分类名称"`
  97. Title string `description:"标题"`
  98. Abstract string `description:"摘要"`
  99. Author string `description:"作者"`
  100. Frequency string `description:"频度"`
  101. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  102. Stage int `description:"期数"`
  103. Content string `description:"内容"`
  104. VideoUrl string `description:"音频文件URL"`
  105. VideoName string `description:"音频文件名称"`
  106. VideoPlaySeconds string `description:"音频播放时长"`
  107. VideoSize string `description:"音频文件大小,单位M"`
  108. AdminId int `description:"创建者账号"`
  109. AdminRealName string `description:"创建者姓名"`
  110. ApproveTime string `description:"审批时间"`
  111. PublishTime string `description:"发布时间"`
  112. CreateTime string `description:"创建时间"`
  113. ModifyTime string `description:"修改时间"`
  114. }
  115. func FormatEnglishReport2Item(origin *EnglishReport) (item *EnglishReportItem) {
  116. if origin == nil {
  117. return
  118. }
  119. item = new(EnglishReportItem)
  120. item.Id = origin.Id
  121. item.ReportCode = origin.ReportCode
  122. item.ClassifyIdFirst = origin.ClassifyIdFirst
  123. item.ClassifyNameFirst = origin.ClassifyNameFirst
  124. item.ClassifyIdSecond = origin.ClassifyIdSecond
  125. item.ClassifyNameSecond = origin.ClassifyNameSecond
  126. item.Title = origin.Title
  127. item.Abstract = origin.Abstract
  128. item.Author = origin.Author
  129. item.Frequency = origin.Frequency
  130. item.State = origin.State
  131. item.Stage = origin.Stage
  132. item.Content = origin.Content
  133. item.VideoUrl = origin.VideoUrl
  134. item.VideoName = origin.VideoName
  135. item.VideoPlaySeconds = origin.VideoPlaySeconds
  136. item.VideoSize = origin.VideoSize
  137. item.AdminId = origin.AdminId
  138. item.AdminRealName = origin.AdminRealName
  139. item.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, origin.ApproveTime)
  140. item.PublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PublishTime)
  141. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  142. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  143. return
  144. }
  145. type EnglishReportListResp struct {
  146. List []*EnglishReportItem
  147. Paging *paging.PagingItem `description:"分页数据"`
  148. }
  149. // EnglishReportApproveReq 英文研报审批请求体
  150. type EnglishReportApproveReq struct {
  151. ReportId int `description:"报告ID"`
  152. Pass bool `description:"是否通过审批"`
  153. }
  154. type ElasticEnglishReportDetail struct {
  155. Id string `description:"报告id或者线上路演Id"`
  156. ReportId int `description:"报告id"`
  157. VideoId int `description:"线上路演Id"`
  158. ClassifyIdFirst int `description:"一级分类id"`
  159. ClassifyNameFirst string `description:"一级分类名称"`
  160. ClassifyIdSecond int `description:"二级分类id"`
  161. ClassifyNameSecond string `description:"二级分类名称"`
  162. StageStr string `description:"报告期数"`
  163. Title string `description:"标题"`
  164. Abstract string `description:"摘要"`
  165. Author string `description:"作者"`
  166. Frequency string `description:"频度"`
  167. PublishState int `description:"状态:1:未发布,2:已发布"`
  168. BodyContent string `description:"内容"`
  169. ContentSub string `description:"前两段内容"`
  170. CreateTime string `description:"创建时间"`
  171. PublishTime string `description:"发布时间"`
  172. ReportCode string `description:"报告唯一编码"`
  173. Overview string `description:"英文概述部分"`
  174. }
  175. type EnglishClassifyList struct {
  176. Id int `orm:"column(id);pk"`
  177. ClassifyName string `description:"分类名称"`
  178. Sort int `description:"排序"`
  179. ParentId int `description:"父级分类id"`
  180. RootId int `description:"一级分类ID"`
  181. CreateTime string `description:"创建时间"`
  182. ModifyTime string `description:"修改时间"`
  183. ClassifyLabel string `description:"分类标签"`
  184. ShowType int `json:"-" description:"展示类型:1-列表 2-专栏"`
  185. IsShow int `json:"-" description:"是否在小程序显示:1-显示 0-隐藏"`
  186. //ClassifyType int `description:"分类类型:0英文报告,1英文线上路演"`
  187. EnPermissions []int `description:"英文权限IDs"`
  188. Child []*EnglishClassifyList
  189. }
  190. type EnglishClassifyListResp struct {
  191. List []*EnglishClassifyList
  192. Paging *paging.PagingItem `description:"分页数据"`
  193. }
  194. // GetEnglishClassifyRootId 获取一级分类列表
  195. func GetEnglishClassifyRootId(startSize, pageSize int, keyword string) (items []*EnglishClassifyList, err error) {
  196. sql := ``
  197. o := orm.NewOrmUsingDB("rddp")
  198. if keyword != "" {
  199. sql = `SELECT * FROM (
  200. SELECT * FROM english_classify
  201. WHERE parent_id=0 AND classify_name ?
  202. UNION
  203. SELECT * FROM english_classify
  204. WHERE id IN(SELECT parent_id FROM english_classify
  205. WHERE parent_id>0 AND classify_name LIKE ?)
  206. )AS t
  207. ORDER BY sort ASC,create_time ASC
  208. LIMIT ?,? `
  209. _, err = o.Raw(sql, utils.GetLikeKeyword(keyword), utils.GetLikeKeyword(keyword), startSize, pageSize).QueryRows(&items)
  210. } else {
  211. sql = `SELECT * FROM english_classify WHERE parent_id=0 ORDER BY sort ASC,create_time ASC LIMIT ?,? `
  212. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  213. }
  214. return
  215. }
  216. func GetEnglishClassifyListCount(keyword string) (count int, err error) {
  217. sqlCount := ``
  218. o := orm.NewOrmUsingDB("rddp")
  219. if keyword != "" {
  220. sqlCount = `SELECT COUNT(1) AS count FROM (
  221. SELECT * FROM english_classify
  222. WHERE parent_id=0 AND classify_name LIKE ?
  223. UNION
  224. SELECT * FROM english_classify
  225. WHERE id IN(SELECT parent_id FROM english_classify
  226. WHERE parent_id>0 AND classify_name LIKE ?)
  227. )AS t `
  228. err = o.Raw(sqlCount, utils.GetLikeKeyword(keyword), utils.GetLikeKeyword(keyword)).QueryRow(&count)
  229. } else {
  230. sqlCount = `SELECT COUNT(1) AS count FROM english_classify WHERE parent_id=0`
  231. err = o.Raw(sqlCount).QueryRow(&count)
  232. }
  233. return
  234. }
  235. func GetEnglishClassifyListByRootId(rootIds []int, keyword string) (items []*EnglishClassifyList, err error) {
  236. sql := ``
  237. pars := make([]interface{}, 0)
  238. o := orm.NewOrmUsingDB("rddp")
  239. if keyword != "" {
  240. sql = `SELECT
  241. a.*
  242. FROM
  243. english_classify a
  244. LEFT JOIN english_classify b ON a.root_id = b.id
  245. LEFT JOIN english_classify c ON a.parent_id = c.id
  246. WHERE a.parent_id>0 and a.classify_name LIKE ? and a.root_id IN (` + utils.GetOrmInReplace(len(rootIds)) + `)`
  247. pars = append(pars, utils.GetLikeKeyword(keyword))
  248. pars = append(pars, rootIds)
  249. _, err = o.Raw(sql, pars).QueryRows(&items)
  250. } else {
  251. sql = `SELECT * FROM english_classify WHERE parent_id>0 and root_id IN (` + utils.GetOrmInReplace(len(rootIds)) + `) `
  252. _, err = o.Raw(sql, rootIds).QueryRows(&items)
  253. }
  254. return
  255. }
  256. type RSChildClassifyList []*EnglishClassifyList
  257. func (m RSChildClassifyList) Len() int {
  258. return len(m)
  259. }
  260. func (m RSChildClassifyList) Less(i, j int) bool {
  261. return m[i].Sort < m[j].Sort
  262. }
  263. func (m RSChildClassifyList) Swap(i, j int) {
  264. m[i], m[j] = m[j], m[i]
  265. }
  266. func GetEnglishClassifyChildByIds(ids []int) (items []*EnglishClassifyList, err error) {
  267. o := orm.NewOrmUsingDB("rddp")
  268. sql := `SELECT * FROM english_classify WHERE id IN (` + utils.GetOrmInReplace(len(ids)) + `) ORDER BY create_time ASC `
  269. _, err = o.Raw(sql, ids).QueryRows(&items)
  270. return
  271. }
  272. type RSClassifyList []*EnglishClassifyList
  273. func (m RSClassifyList) Len() int {
  274. return len(m)
  275. }
  276. func (m RSClassifyList) Less(i, j int) bool {
  277. return m[i].Sort < m[j].Sort
  278. }
  279. func (m RSClassifyList) Swap(i, j int) {
  280. m[i], m[j] = m[j], m[i]
  281. }