report.go 17 KB

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