english_report.go 11 KB

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