report.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/utils"
  6. "strings"
  7. "time"
  8. )
  9. type Report struct {
  10. Id int `orm:"column(id)" description:"报告Id"`
  11. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  12. ClassifyIdFirst int `description:"一级分类id"`
  13. ClassifyNameFirst string `description:"一级分类名称"`
  14. ClassifyIdSecond int `description:"二级分类id"`
  15. ClassifyNameSecond string `description:"二级分类名称"`
  16. Title string `description:"标题"`
  17. Abstract string `description:"摘要"`
  18. Author string `description:"作者"`
  19. Frequency string `description:"频度"`
  20. CreateTime string `description:"创建时间"`
  21. ModifyTime time.Time `description:"修改时间"`
  22. State int `description:"1:未发布,2:已发布"`
  23. PublishTime time.Time `description:"发布时间"`
  24. Stage int `description:"期数"`
  25. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  26. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  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. ReportVersion int `description:"1:旧版,2:新版"`
  35. HasChapter int `description:"是否有章节 0-否 1-是"`
  36. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  37. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  38. MsgSendTime time.Time `description:"模版消息发送时间"`
  39. AdminId int `description:"创建者账号"`
  40. AdminRealName string `description:"创建者姓名"`
  41. }
  42. type ReportList struct {
  43. Id int `description:"报告Id"`
  44. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  45. ClassifyIdFirst int `description:"一级分类id"`
  46. ClassifyNameFirst string `description:"一级分类名称"`
  47. ClassifyIdSecond int `description:"二级分类id"`
  48. ClassifyNameSecond string `description:"二级分类名称"`
  49. Title string `description:"标题"`
  50. Abstract string `description:"摘要"`
  51. Author string `description:"作者"`
  52. Frequency string `description:"频度"`
  53. CreateTime string `description:"创建时间"`
  54. ModifyTime time.Time `description:"修改时间"`
  55. State int `description:"1:未发布,2:已发布"`
  56. PublishTime string `description:"发布时间"`
  57. Stage int `description:"期数"`
  58. MsgIsSend int `description:"模板消息是否已发送,0:否,1:是"`
  59. Content string `description:"内容"`
  60. VideoUrl string `description:"音频文件URL"`
  61. VideoName string `description:"音频文件名称"`
  62. VideoPlaySeconds string `description:"音频播放时长"`
  63. ContentSub string `description:"内容前两个章节"`
  64. Pv int `description:"Pv"`
  65. Uv int `description:"Uv"`
  66. ReportCode string `description:"报告唯一编码"`
  67. ReportVersion int `description:"1:旧版,2:新版"`
  68. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  69. NeedThsMsg int `description:"是否需要推送客群消息 0-否 1-是"`
  70. HasChapter int `description:"是否有章节 0-否 1-是"`
  71. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  72. //ChapterVideoList []*ReportChapterVideoList `description:"章节音频列表"`
  73. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  74. MsgSendTime string `description:"模版消息发送时间"`
  75. CanEdit bool `description:"是否可编辑"`
  76. Editor string `description:"编辑人"`
  77. AdminId int `description:"创建者账号"`
  78. AdminRealName string `description:"创建者姓名"`
  79. }
  80. type ReportListResp struct {
  81. List []*ReportList
  82. Paging *paging.PagingItem `description:"分页数据"`
  83. }
  84. type ReportDetail struct {
  85. Id int `orm:"column(id)" description:"报告Id"`
  86. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  87. ClassifyIdFirst int `description:"一级分类id"`
  88. ClassifyNameFirst string `description:"一级分类名称"`
  89. ClassifyIdSecond int `description:"二级分类id"`
  90. ClassifyNameSecond string `description:"二级分类名称"`
  91. Title string `description:"标题"`
  92. Abstract string `description:"摘要"`
  93. Author string `description:"作者"`
  94. Frequency string `description:"频度"`
  95. CreateTime string `description:"创建时间"`
  96. ModifyTime string `description:"修改时间"`
  97. State int `description:"1:未发布,2:已发布"`
  98. PublishTime string `description:"发布时间"`
  99. Stage int `description:"期数"`
  100. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  101. Content string `description:"内容"`
  102. VideoUrl string `description:"音频文件URL"`
  103. VideoName string `description:"音频文件名称"`
  104. VideoPlaySeconds string `description:"音频播放时长"`
  105. ContentSub string `description:"内容前两个章节"`
  106. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  107. HasChapter int `description:"是否有章节 0-否 1-是"`
  108. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  109. }
  110. func GetReportById(reportId int) (item *ReportDetail, err error) {
  111. o := orm.NewOrmUsingDB("rddp")
  112. sql := `SELECT * FROM report WHERE id=?`
  113. err = o.Raw(sql, reportId).QueryRow(&item)
  114. return
  115. }
  116. func GetReportByIds(reportIds string) (list []*ReportDetail, err error) {
  117. o := orm.NewOrmUsingDB("rddp")
  118. sql := `SELECT * FROM report WHERE id in ` + reportIds
  119. _, err = o.Raw(sql).QueryRows(&list)
  120. return
  121. }
  122. // GetReportByIdList 根据报告id列表获取报告列表
  123. func GetReportByIdList(reportIdList []int) (list []*ReportDetail, err error) {
  124. num := len(reportIdList)
  125. if num <= 0 {
  126. return
  127. }
  128. o := orm.NewOrmUsingDB("rddp")
  129. sql := `SELECT * FROM report WHERE id in (` + utils.GetOrmInReplace(num) + `)`
  130. _, err = o.Raw(sql, reportIdList).QueryRows(&list)
  131. return
  132. }
  133. // GetSimpleReportByIds 根据报告ID查询报告基本信息
  134. func GetSimpleReportByIds(reportIds string) (list []*ReportDetail, err error) {
  135. o := orm.NewOrmUsingDB("rddp")
  136. sql := `SELECT id, title FROM report WHERE id IN (` + reportIds + `)`
  137. _, err = o.Raw(sql).QueryRows(&list)
  138. return
  139. }
  140. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  141. o := orm.NewOrmUsingDB("rddp")
  142. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  143. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  144. return
  145. }
  146. type ReportItem struct {
  147. Id int `orm:"column(id)" description:"报告Id"`
  148. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  149. ClassifyIdFirst int `description:"一级分类id"`
  150. ClassifyNameFirst string `description:"一级分类名称"`
  151. ClassifyIdSecond int `description:"二级分类id"`
  152. ClassifyNameSecond string `description:"二级分类名称"`
  153. Title string `description:"标题"`
  154. Abstract string `description:"摘要"`
  155. Author string `description:"作者"`
  156. Frequency string `description:"频度"`
  157. CreateTime time.Time `description:"创建时间"`
  158. ModifyTime time.Time `description:"修改时间"`
  159. State int `description:"1:未发布,2:已发布"`
  160. PublishTime time.Time `description:"发布时间"`
  161. Stage int `description:"期数"`
  162. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  163. Content string `description:"内容"`
  164. VideoUrl string `description:"音频文件URL"`
  165. VideoName string `description:"音频文件名称"`
  166. VideoPlaySeconds string `description:"音频播放时长"`
  167. ContentSub string `description:"内容前两个章节"`
  168. }
  169. func GetReportItemById(reportId int) (item *ReportItem, err error) {
  170. o := orm.NewOrmUsingDB("rddp")
  171. sql := `SELECT * FROM report WHERE id=?`
  172. err = o.Raw(sql, reportId).QueryRow(&item)
  173. return
  174. }
  175. // GetCommentReportByReportId 查询有留言的报告列表
  176. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  177. o := orm.NewOrmUsingDB("rddp")
  178. sql := `SELECT
  179. id,
  180. create_time,
  181. title,
  182. classify_name_first,
  183. classify_id_first,
  184. classify_name_second,
  185. classify_id_second,
  186. state,
  187. IF
  188. ( publish_time, publish_time, create_time ) AS publish_time
  189. FROM
  190. report
  191. WHERE
  192. 1=1
  193. `
  194. if condition != "" {
  195. sql += condition
  196. }
  197. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  198. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  199. return
  200. }
  201. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  202. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  203. o := orm.NewOrmUsingDB("rddp")
  204. sql := `SELECT
  205. id,
  206. create_time,
  207. title,
  208. classify_name_first,
  209. classify_id_first,
  210. classify_name_second,
  211. classify_id_second,
  212. state,
  213. IF
  214. ( publish_time, publish_time, create_time ) AS publish_time
  215. FROM
  216. report
  217. WHERE
  218. 1=1
  219. `
  220. if condition != "" {
  221. sql += condition
  222. }
  223. if orderBy == `` {
  224. sql += ` ORDER BY publish_time DESC , title ASC `
  225. } else {
  226. sql += orderBy
  227. }
  228. sql += ` LIMIT ?,? `
  229. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  230. return
  231. }
  232. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  233. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  234. o := orm.NewOrmUsingDB("rddp")
  235. sql := `SELECT count(*)
  236. FROM report WHERE 1=1`
  237. if condition != "" {
  238. sql += condition
  239. }
  240. err = o.Raw(sql, pars).QueryRow(&total)
  241. return
  242. }
  243. // 点赞相关的报告列表
  244. type LikeReportItem struct {
  245. ReportId int `description:"报告Id"`
  246. ReportChapterId int `description:"报告章节Id"`
  247. ClassifyIdFirst int `description:"一级分类id"`
  248. ClassifyNameFirst string `description:"一级分类名称"`
  249. ClassifyIdSecond int `description:"二级分类id"`
  250. ClassifyNameSecond string `description:"二级分类名称"`
  251. ReportChapterTypeId int `description:"章节类型"`
  252. ReportChapterTypeName string `description:"品种名称"`
  253. PublishTime time.Time `description:"发布时间" `
  254. Title string `description:"标题"`
  255. }
  256. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  257. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  258. o := orm.NewOrmUsingDB("rddp")
  259. sql := `( SELECT
  260. id AS report_id,
  261. 0 AS report_chapter_id,
  262. classify_id_first,
  263. classify_id_second,
  264. classify_name_first,
  265. classify_name_second,
  266. 0 as report_chapter_type_id,
  267. "" as report_chapter_type_name,
  268. publish_time,
  269. title
  270. FROM
  271. report
  272. WHERE
  273. classify_name_first != "晨报"
  274. AND classify_name_first != "周报"
  275. AND id in (` + reportIds + `)
  276. )
  277. UNION
  278. ( SELECT
  279. report_id,
  280. report_chapter_id,
  281. classify_id_first,
  282. 0 as classify_id_second,
  283. classify_name_first,
  284. null as classify_name_second,
  285. type_id as report_chapter_type_id,
  286. type_name as report_chapter_type_name,
  287. publish_time,
  288. title
  289. FROM
  290. report_chapter
  291. WHERE
  292. report_chapter_id in (` + chapterIds + `)
  293. )`
  294. if orderStr != "" {
  295. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  296. } else {
  297. sql += ` ORDER BY publish_time DESC, report_id Desc`
  298. }
  299. sql += ` LIMIT ?,?`
  300. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  301. return
  302. }
  303. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  304. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  305. o := orm.NewOrmUsingDB("rddp")
  306. sql := `select count(*) from (( SELECT
  307. id AS report_id,
  308. 0 AS report_chapter_id,
  309. classify_id_first,
  310. classify_id_second,
  311. classify_name_first,
  312. classify_name_second,
  313. 0 as report_chapter_type_id,
  314. publish_time,
  315. title
  316. FROM
  317. report
  318. WHERE
  319. classify_name_first != "晨报"
  320. AND classify_name_first != "周报"
  321. AND id in (` + reportIds + `)
  322. )
  323. UNION
  324. ( SELECT
  325. report_id,
  326. report_chapter_id,
  327. classify_id_first,
  328. 0 as classify_id_second,
  329. classify_name_first,
  330. null as classify_name_second,
  331. type_id as report_chapter_type_id,
  332. publish_time,
  333. title
  334. FROM
  335. report_chapter
  336. WHERE
  337. report_chapter_id in (` + chapterIds + `)
  338. )) r`
  339. err = o.Raw(sql).QueryRow(&total)
  340. return
  341. }
  342. // GetPageReportList 分页获取报告列表
  343. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  344. o := orm.NewOrmUsingDB("rddp")
  345. sql := `SELECT * FROM report WHERE 1=1 `
  346. sql += condition
  347. sql += ` ORDER BY modify_time DESC`
  348. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  349. err = o.Raw(totalSql, pars).QueryRow(&total)
  350. if err != nil {
  351. return
  352. }
  353. sql += ` LIMIT ?,? `
  354. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  355. return
  356. }
  357. // YbPcSuncode 活动海报表
  358. type YbPcSuncode struct {
  359. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  360. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  361. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  362. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  363. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  364. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  365. }
  366. // GetYbPcSunCode 获取太阳码
  367. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  368. o := orm.NewOrmUsingDB("default")
  369. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  370. err = o.Raw(sql, scene, page).QueryRow(&item)
  371. return
  372. }
  373. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  374. o := orm.NewOrmUsingDB("default")
  375. _, err = o.Insert(item)
  376. return
  377. }
  378. // YbSuncodePars 小程序太阳码scene参数
  379. type YbSuncodePars struct {
  380. ID uint32 `orm:"column(id);pk" `
  381. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  382. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  383. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  384. }
  385. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  386. o := orm.NewOrmUsingDB("default")
  387. _, err = o.Insert(item)
  388. return
  389. }
  390. // GetReportByCondition 获取报告
  391. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  392. o := orm.NewOrmUsingDB("rddp")
  393. fields := `*`
  394. if len(fieldArr) > 0 {
  395. fields = strings.Join(fieldArr, ",")
  396. }
  397. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  398. sql += condition
  399. order := ` ORDER BY modify_time DESC`
  400. if orderRule != `` {
  401. order = orderRule
  402. }
  403. sql += order
  404. if isPage {
  405. sql += ` LIMIT ?,?`
  406. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  407. } else {
  408. _, err = o.Raw(sql, pars).QueryRows(&items)
  409. }
  410. return
  411. }