report.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "strings"
  6. "time"
  7. )
  8. type Report 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. Stage int `description:"期数"`
  24. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  25. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  26. Content string `description:"内容"`
  27. VideoUrl string `description:"音频文件URL"`
  28. VideoName string `description:"音频文件名称"`
  29. VideoPlaySeconds string `description:"音频播放时长"`
  30. VideoSize string `description:"音频文件大小,单位M"`
  31. ContentSub string `description:"内容前两个章节"`
  32. ReportCode string `description:"报告唯一编码"`
  33. ReportVersion int `description:"1:旧版,2:新版"`
  34. HasChapter int `description:"是否有章节 0-否 1-是"`
  35. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  36. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  37. MsgSendTime time.Time `description:"模版消息发送时间"`
  38. AdminId int `description:"创建者账号"`
  39. AdminRealName string `description:"创建者姓名"`
  40. }
  41. type ReportList struct {
  42. Id int `description:"报告Id"`
  43. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  44. ClassifyIdFirst int `description:"一级分类id"`
  45. ClassifyNameFirst string `description:"一级分类名称"`
  46. ClassifyIdSecond int `description:"二级分类id"`
  47. ClassifyNameSecond string `description:"二级分类名称"`
  48. Title string `description:"标题"`
  49. Abstract string `description:"摘要"`
  50. Author string `description:"作者"`
  51. Frequency string `description:"频度"`
  52. CreateTime string `description:"创建时间"`
  53. ModifyTime time.Time `description:"修改时间"`
  54. State int `description:"1:未发布,2:已发布"`
  55. PublishTime string `description:"发布时间"`
  56. PrePublishTime 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. func GetReportListCount(condition string, pars []interface{}, companyType string) (count int, err error) {
  85. //产品权限
  86. companyTypeSqlStr := ``
  87. if companyType == "ficc" {
  88. companyTypeSqlStr = " AND classify_id_first != 40 "
  89. } else if companyType == "权益" {
  90. companyTypeSqlStr = " AND classify_id_first = 40 "
  91. }
  92. oRddp := orm.NewOrmUsingDB("rddp")
  93. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 ` + companyTypeSqlStr
  94. if condition != "" {
  95. sql += condition
  96. }
  97. err = oRddp.Raw(sql, pars).QueryRow(&count)
  98. return
  99. }
  100. func GetReportList(condition string, pars []interface{}, companyType string, startSize, pageSize int) (items []*ReportList, err error) {
  101. o := orm.NewOrmUsingDB("rddp")
  102. //产品权限
  103. companyTypeSqlStr := ``
  104. if companyType == "ficc" {
  105. companyTypeSqlStr = " AND classify_id_first != 40 "
  106. } else if companyType == "权益" {
  107. companyTypeSqlStr = " AND classify_id_first = 40 "
  108. }
  109. sql := `SELECT *,
  110. (SELECT COUNT(1) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS pv,
  111. (SELECT COUNT(DISTINCT user_id) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS uv
  112. FROM report WHERE 1=1 ` + companyTypeSqlStr
  113. if condition != "" {
  114. sql += condition
  115. }
  116. sql += `ORDER BY state ASC, modify_time DESC LIMIT ?,?`
  117. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  118. return
  119. }
  120. // 发布报告
  121. func PublishReport(reportIds string) (err error) {
  122. o := orm.NewOrmUsingDB("rddp")
  123. sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + reportIds + `)`
  124. _, err = o.Raw(sql).Exec()
  125. return
  126. }
  127. // 取消发布报告
  128. func PublishCancleReport(reportIds int, publishTimeNullFlag bool) (err error) {
  129. o := orm.NewOrmUsingDB("rddp")
  130. var sql string
  131. if publishTimeNullFlag {
  132. sql = ` UPDATE report SET state=1, publish_time=null, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  133. } else {
  134. sql = ` UPDATE report SET state=1, pre_publish_time=null, pre_msg_send=0 WHERE id =?`
  135. }
  136. _, err = o.Raw(sql, reportIds).Exec()
  137. return
  138. }
  139. // 删除报告
  140. func DeleteReport(reportIds int) (err error) {
  141. o := orm.NewOrmUsingDB("rddp")
  142. sql := ` DELETE FROM report WHERE id =? `
  143. _, err = o.Raw(sql, reportIds).Exec()
  144. return
  145. }
  146. type ReportDetail 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 string `description:"创建时间"`
  158. ModifyTime string `description:"修改时间"`
  159. State int `description:"1:未发布,2:已发布"`
  160. PublishTime string `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. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  169. HasChapter int `description:"是否有章节 0-否 1-是"`
  170. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  171. }
  172. func GetReportById(reportId int) (item *ReportDetail, err error) {
  173. o := orm.NewOrmUsingDB("rddp")
  174. sql := `SELECT * FROM report WHERE id=?`
  175. err = o.Raw(sql, reportId).QueryRow(&item)
  176. return
  177. }
  178. func GetReportByIds(reportIds string) (list []*ReportDetail, err error) {
  179. o := orm.NewOrmUsingDB("rddp")
  180. sql := `SELECT * FROM report WHERE id in ` + reportIds
  181. _, err = o.Raw(sql).QueryRows(&list)
  182. return
  183. }
  184. // GetSimpleReportByIds 根据报告ID查询报告基本信息
  185. func GetSimpleReportByIds(reportIds string) (list []*ReportDetail, err error) {
  186. o := orm.NewOrmUsingDB("rddp")
  187. sql := `SELECT id, title FROM report WHERE id IN (` + reportIds + `)`
  188. _, err = o.Raw(sql).QueryRows(&list)
  189. return
  190. }
  191. func GetReportStage(classifyIdFirst, classifyIdSecond int) (count int, err error) {
  192. o := orm.NewOrmUsingDB("rddp")
  193. sql := ``
  194. if classifyIdSecond > 0 {
  195. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? "
  196. o.Raw(sql, classifyIdSecond).QueryRow(&count)
  197. } else {
  198. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? "
  199. o.Raw(sql, classifyIdFirst).QueryRow(&count)
  200. }
  201. return
  202. }
  203. func GetReportStageEdit(classifyIdFirst, classifyIdSecond, reportId int) (count int, err error) {
  204. o := orm.NewOrmUsingDB("rddp")
  205. sql := ``
  206. if classifyIdSecond > 0 {
  207. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_second=? AND id<>? "
  208. o.Raw(sql, classifyIdSecond, reportId).QueryRow(&count)
  209. } else {
  210. sql = "SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first=? AND id<>? "
  211. o.Raw(sql, classifyIdFirst, reportId).QueryRow(&count)
  212. }
  213. return
  214. }
  215. type PublishReq struct {
  216. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  217. }
  218. type PublishCancelReq struct {
  219. ReportIds int `description:"报告id"`
  220. }
  221. type DeleteReq struct {
  222. ReportIds int `description:"报告id"`
  223. }
  224. type AddReq struct {
  225. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  226. ClassifyIdFirst int `description:"一级分类id"`
  227. ClassifyNameFirst string `description:"一级分类名称"`
  228. ClassifyIdSecond int `description:"二级分类id"`
  229. ClassifyNameSecond string `description:"二级分类名称"`
  230. Title string `description:"标题"`
  231. Abstract string `description:"摘要"`
  232. Author string `description:"作者"`
  233. Frequency string `description:"频度"`
  234. State int `description:"状态:1:未发布,2:已发布"`
  235. Content string `description:"内容"`
  236. CreateTime string `description:"创建时间"`
  237. ReportVersion int `description:"1:旧版,2:新版"`
  238. }
  239. type PrePublishReq struct {
  240. ReportId int `description:"报告id"`
  241. PrePublishTime string `description:"预发布时间"`
  242. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  243. }
  244. type AddResp struct {
  245. ReportId int64 `description:"报告id"`
  246. ReportCode string `description:"报告code"`
  247. }
  248. func AddReport(item *Report) (lastId int64, err error) {
  249. o := orm.NewOrmUsingDB("rddp")
  250. lastId, err = o.Insert(item)
  251. return
  252. }
  253. type EditReq struct {
  254. ReportId int64 `description:"报告id"`
  255. ClassifyIdFirst int `description:"一级分类id"`
  256. ClassifyNameFirst string `description:"一级分类名称"`
  257. ClassifyIdSecond int `description:"二级分类id"`
  258. ClassifyNameSecond string `description:"二级分类名称"`
  259. Title string `description:"标题"`
  260. Abstract string `description:"摘要"`
  261. Author string `description:"作者"`
  262. Frequency string `description:"频度"`
  263. State int `description:"状态:1:未发布,2:已发布"`
  264. Content string `description:"内容"`
  265. CreateTime string `description:"创建时间"`
  266. }
  267. type EditResp struct {
  268. ReportId int64 `description:"报告id"`
  269. ReportCode string `description:"报告code"`
  270. }
  271. func EditReport(item *Report, reportId int64) (err error) {
  272. o := orm.NewOrmUsingDB("rddp")
  273. sql := `UPDATE report
  274. SET
  275. classify_id_first =?,
  276. classify_name_first = ?,
  277. classify_id_second = ?,
  278. classify_name_second = ?,
  279. title = ?,
  280. abstract = ?,
  281. author = ?,
  282. frequency = ?,
  283. state = ?,
  284. content = ?,
  285. content_sub = ?,
  286. stage =?,
  287. create_time = ?,
  288. modify_time = ?
  289. WHERE id = ? `
  290. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  291. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec()
  292. return
  293. }
  294. type ReportDetailReq struct {
  295. ReportId int `description:"报告id"`
  296. }
  297. type ClassifyIdDetailReq struct {
  298. ClassifyIdFirst int `description:"报告一级分类id"`
  299. ClassifyIdSecond int `description:"报告二级分类id"`
  300. }
  301. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  302. o := orm.NewOrmUsingDB("rddp")
  303. sql := ` SELECT * FROM report WHERE 1=1 `
  304. if classifyIdSecond > 0 {
  305. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  306. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  307. } else {
  308. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  309. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  310. }
  311. return
  312. }
  313. type SendTemplateMsgReq struct {
  314. ReportId int `description:"报告id"`
  315. }
  316. func ModifyReportMsgIsSend(reportId int) (err error) {
  317. o := orm.NewOrmUsingDB("rddp")
  318. report, err := GetReportById(reportId)
  319. if err != nil {
  320. return
  321. }
  322. if report.MsgIsSend == 0 {
  323. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  324. _, err = o.Raw(sql, reportId).Exec()
  325. }
  326. return
  327. }
  328. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  329. o := orm.NewOrmUsingDB("rddp")
  330. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  331. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  332. return
  333. }
  334. type ReportItem struct {
  335. Id int `orm:"column(id)" description:"报告Id"`
  336. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  337. ClassifyIdFirst int `description:"一级分类id"`
  338. ClassifyNameFirst string `description:"一级分类名称"`
  339. ClassifyIdSecond int `description:"二级分类id"`
  340. ClassifyNameSecond string `description:"二级分类名称"`
  341. Title string `description:"标题"`
  342. Abstract string `description:"摘要"`
  343. Author string `description:"作者"`
  344. Frequency string `description:"频度"`
  345. CreateTime time.Time `description:"创建时间"`
  346. ModifyTime time.Time `description:"修改时间"`
  347. State int `description:"1:未发布,2:已发布"`
  348. PublishTime time.Time `description:"发布时间"`
  349. Stage int `description:"期数"`
  350. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  351. Content string `description:"内容"`
  352. VideoUrl string `description:"音频文件URL"`
  353. VideoName string `description:"音频文件名称"`
  354. VideoPlaySeconds string `description:"音频播放时长"`
  355. ContentSub string `description:"内容前两个章节"`
  356. }
  357. func GetReportItemById(reportId int) (item *ReportItem, err error) {
  358. o := orm.NewOrmUsingDB("rddp")
  359. sql := `SELECT * FROM report WHERE id=?`
  360. err = o.Raw(sql, reportId).QueryRow(&item)
  361. return
  362. }
  363. type SaveReportContent struct {
  364. Content string `description:"内容"`
  365. ReportId int `description:"报告id"`
  366. NoChange int `description:"内容是否未改变:1:内容未改变"`
  367. }
  368. func EditReportContent(reportId int, content, contentSub string) (err error) {
  369. o := orm.NewOrmUsingDB("rddp")
  370. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  371. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  372. return
  373. }
  374. func AddReportSaveLog(reportId, adminId int, content, contentSub, adminName string) (err error) {
  375. o := orm.NewOrmUsingDB("rddp")
  376. sql := ` INSERT INTO report_save_log(report_id, content,content_sub,admin_id,admin_name) VALUES (?,?,?,?,?) `
  377. _, err = o.Raw(sql, reportId, content, contentSub, adminId, adminName).Exec()
  378. return
  379. }
  380. type SaveReportContentResp struct {
  381. ReportId int `description:"报告id"`
  382. }
  383. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  384. o := orm.NewOrmUsingDB("rddp")
  385. sql := `UPDATE report SET report_code=? WHERE id=? `
  386. _, err = o.Raw(sql, reportCode, reportId).Exec()
  387. return
  388. }
  389. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  390. o := orm.NewOrmUsingDB("rddp")
  391. if item.ThsMsgIsSend == 0 {
  392. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  393. _, err = o.Raw(sql, item.Id).Exec()
  394. }
  395. return
  396. }
  397. type ThsSendTemplateMsgReq struct {
  398. ReportId []int `description:"报告id"`
  399. }
  400. type PublishDayWeekReportReq struct {
  401. ReportId int `description:"报告ID"`
  402. }
  403. // SaveDayWeekReportReq 新增晨报周报请求体
  404. type SaveDayWeekReportReq struct {
  405. ReportId int `description:"报告ID"`
  406. Title string `description:"标题"`
  407. ReportType string `description:"一级分类ID"`
  408. Author string `description:"作者"`
  409. CreateTime string `description:"创建时间"`
  410. }
  411. // GetDayWeekReportStage 获取晨报周报期数
  412. func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  413. o := orm.NewOrmUsingDB("rddp")
  414. sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  415. o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  416. return
  417. }
  418. // AddReportAndChapter 新增报告及章节
  419. func AddReportAndChapter(reportItem *Report, chapterItemList []*ReportChapter) (reportId int64, err error) {
  420. o := orm.NewOrmUsingDB("rddp")
  421. to, err := o.Begin()
  422. if err != nil {
  423. return
  424. }
  425. defer func() {
  426. if err != nil {
  427. _ = to.Rollback()
  428. } else {
  429. _ = to.Commit()
  430. }
  431. }()
  432. if reportId, err = to.Insert(reportItem); err != nil {
  433. return
  434. }
  435. if len(chapterItemList) > 0 {
  436. for _, chapterItem := range chapterItemList {
  437. chapterItem.ReportId = int(reportId)
  438. if _, tmpErr := to.Insert(chapterItem); tmpErr != nil {
  439. return
  440. }
  441. }
  442. }
  443. return
  444. }
  445. // GetReportByReportId 主键获取报告
  446. func GetReportByReportId(reportId int) (item *Report, err error) {
  447. o := orm.NewOrmUsingDB("rddp")
  448. sql := `SELECT * FROM report WHERE id = ?`
  449. err = o.Raw(sql, reportId).QueryRow(&item)
  450. return
  451. }
  452. // GetReportByOldReportId 根据老报告id主键获取报告
  453. func GetReportByOldReportId(reportId int) (item *Report, err error) {
  454. o := orm.NewOrmUsingDB("rddp")
  455. sql := `SELECT * FROM report WHERE old_report_id = ?`
  456. err = o.Raw(sql, reportId).QueryRow(&item)
  457. return
  458. }
  459. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  460. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  461. o := orm.NewOrmUsingDB("rddp")
  462. to, err := o.Begin()
  463. if err != nil {
  464. return
  465. }
  466. defer func() {
  467. if err != nil {
  468. _ = to.Rollback()
  469. } else {
  470. _ = to.Commit()
  471. }
  472. }()
  473. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  474. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  475. return
  476. }
  477. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  478. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  479. return
  480. }
  481. return
  482. }
  483. // UpdateReport 更新报告
  484. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  485. o := orm.NewOrmUsingDB("rddp")
  486. _, err = o.Update(reportInfo, cols...)
  487. return
  488. }
  489. // 晨周报详情
  490. type ReportDetailView struct {
  491. *ReportDetail
  492. ChapterList []*ReportChapter
  493. }
  494. func GetUnPublishDayReport(startTime time.Time, endTime time.Time) (item *Report, err error) {
  495. o := orm.NewOrmUsingDB("rddp")
  496. sql := ` SELECT
  497. *
  498. FROM
  499. report AS a
  500. WHERE
  501. a.has_chapter = 1
  502. AND a.chapter_type = "day"
  503. AND a.state = 1
  504. AND (
  505. a.create_time BETWEEN ? AND ?
  506. )
  507. ORDER BY
  508. a.create_time DESC
  509. LIMIT 1 `
  510. err = o.Raw(sql, startTime, endTime).QueryRow(&item)
  511. return
  512. }
  513. type ElasticReportDetail struct {
  514. ReportId int `description:"报告ID"`
  515. ReportChapterId int `description:"报告章节ID"`
  516. Title string `description:"标题"`
  517. Abstract string `description:"摘要"`
  518. BodyContent string `description:"内容"`
  519. PublishTime string `description:"发布时间"`
  520. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  521. Author string `description:"作者"`
  522. ClassifyIdFirst int `description:"一级分类ID"`
  523. ClassifyNameFirst string `description:"一级分类名称"`
  524. ClassifyIdSecond int `description:"二级分类ID"`
  525. ClassifyNameSecond string `description:"二级分类名称"`
  526. Categories string `description:"关联的品种名称(包括品种别名)"`
  527. StageStr string `description:"报告期数"`
  528. }
  529. // GetLastPublishedDayWeekReport 获取上一篇已发布的晨周报
  530. func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  531. o := orm.NewOrmUsingDB("rddp")
  532. sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  533. err = o.Raw(sql, chapterType).QueryRow(&item)
  534. return
  535. }
  536. // GetNewReportExist
  537. func GetNewReportExist(oldReportId int) (item *Report, err error) {
  538. o := orm.NewOrmUsingDB("rddp")
  539. sql := ` SELECT id FROM report WHERE old_report_id = ? LIMIT 1 `
  540. err = o.Raw(sql, oldReportId).QueryRow(&item)
  541. return
  542. }
  543. // PublishReportAndChapter 发布报告及章节
  544. func PublishReportAndChapter(reportInfo *Report, publishIds string, unPublishIds string, isPublishReport bool, cols []string) (err error) {
  545. o := orm.NewOrmUsingDB("rddp")
  546. to, err := o.Begin()
  547. if err != nil {
  548. return
  549. }
  550. defer func() {
  551. if err != nil {
  552. _ = to.Rollback()
  553. } else {
  554. _ = to.Commit()
  555. }
  556. }()
  557. // 更新报告
  558. if isPublishReport {
  559. if _, err = to.Update(reportInfo, cols...); err != nil {
  560. return
  561. }
  562. }
  563. // 发布章节
  564. if publishIds != "" {
  565. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + publishIds + `) `
  566. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id).Exec()
  567. }
  568. if unPublishIds != "" {
  569. sql := ` UPDATE report_chapter SET publish_state = 1, publish_time = NULL, is_edit = 0 WHERE report_id = ? AND report_chapter_id IN (` + unPublishIds + `) `
  570. _, err = to.Raw(sql, reportInfo.Id).Exec()
  571. }
  572. return
  573. }
  574. func GetSyncEmptyVideoReport() (list []*Report, err error) {
  575. o := orm.NewOrmUsingDB("rddp")
  576. sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  577. UNION ALL
  578. SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  579. _, err = o.Raw(sql).QueryRows(&list)
  580. return
  581. }
  582. // 发布报告
  583. func PublishReportById(reportId int, publishTime time.Time) (err error) {
  584. o := orm.NewOrmUsingDB("rddp")
  585. sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
  586. _, err = o.Raw(sql, publishTime, reportId).Exec()
  587. return
  588. }
  589. // GetCommentReportByReportId 查询有留言的报告列表
  590. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  591. o := orm.NewOrmUsingDB("rddp")
  592. sql := `SELECT
  593. id,
  594. create_time,
  595. title,
  596. classify_name_first,
  597. classify_id_first,
  598. classify_name_second,
  599. classify_id_second,
  600. state,
  601. IF
  602. ( publish_time, publish_time, create_time ) AS publish_time
  603. FROM
  604. report
  605. WHERE
  606. 1=1
  607. `
  608. if condition != "" {
  609. sql += condition
  610. }
  611. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  612. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  613. return
  614. }
  615. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  616. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  617. o := orm.NewOrmUsingDB("rddp")
  618. sql := `SELECT
  619. id,
  620. create_time,
  621. title,
  622. classify_name_first,
  623. classify_id_first,
  624. classify_name_second,
  625. classify_id_second,
  626. state,
  627. IF
  628. ( publish_time, publish_time, create_time ) AS publish_time
  629. FROM
  630. report
  631. WHERE
  632. 1=1
  633. `
  634. if condition != "" {
  635. sql += condition
  636. }
  637. if orderBy == `` {
  638. sql += ` ORDER BY publish_time DESC , title ASC `
  639. } else {
  640. sql += orderBy
  641. }
  642. sql += ` LIMIT ?,? `
  643. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  644. return
  645. }
  646. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  647. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  648. o := orm.NewOrmUsingDB("rddp")
  649. sql := `SELECT count(*)
  650. FROM report WHERE 1=1`
  651. if condition != "" {
  652. sql += condition
  653. }
  654. err = o.Raw(sql, pars).QueryRow(&total)
  655. return
  656. }
  657. // 点赞相关的报告列表
  658. type LikeReportItem struct {
  659. ReportId int `description:"报告Id"`
  660. ReportChapterId int `description:"报告章节Id"`
  661. ClassifyIdFirst int `description:"一级分类id"`
  662. ClassifyNameFirst string `description:"一级分类名称"`
  663. ClassifyIdSecond int `description:"二级分类id"`
  664. ClassifyNameSecond string `description:"二级分类名称"`
  665. ReportChapterTypeId int `description:"章节类型"`
  666. ReportChapterTypeName string `description:"品种名称"`
  667. PublishTime time.Time `description:"发布时间" `
  668. Title string `description:"标题"`
  669. }
  670. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  671. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  672. o := orm.NewOrmUsingDB("rddp")
  673. sql := `( SELECT
  674. id AS report_id,
  675. 0 AS report_chapter_id,
  676. classify_id_first,
  677. classify_id_second,
  678. classify_name_first,
  679. classify_name_second,
  680. 0 as report_chapter_type_id,
  681. "" as report_chapter_type_name,
  682. publish_time,
  683. title
  684. FROM
  685. report
  686. WHERE
  687. classify_name_first != "晨报"
  688. AND classify_name_first != "周报"
  689. AND id in (` + reportIds + `)
  690. )
  691. UNION
  692. ( SELECT
  693. report_id,
  694. report_chapter_id,
  695. classify_id_first,
  696. 0 as classify_id_second,
  697. classify_name_first,
  698. null as classify_name_second,
  699. type_id as report_chapter_type_id,
  700. type_name as report_chapter_type_name,
  701. publish_time,
  702. title
  703. FROM
  704. report_chapter
  705. WHERE
  706. report_chapter_id in (` + chapterIds + `)
  707. )`
  708. if orderStr != "" {
  709. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  710. } else {
  711. sql += ` ORDER BY publish_time DESC, report_id Desc`
  712. }
  713. sql += ` LIMIT ?,?`
  714. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  715. return
  716. }
  717. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  718. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  719. o := orm.NewOrmUsingDB("rddp")
  720. sql := `select count(*) from (( SELECT
  721. id AS report_id,
  722. 0 AS report_chapter_id,
  723. classify_id_first,
  724. classify_id_second,
  725. classify_name_first,
  726. classify_name_second,
  727. 0 as report_chapter_type_id,
  728. publish_time,
  729. title
  730. FROM
  731. report
  732. WHERE
  733. classify_name_first != "晨报"
  734. AND classify_name_first != "周报"
  735. AND id in (` + reportIds + `)
  736. )
  737. UNION
  738. ( SELECT
  739. report_id,
  740. report_chapter_id,
  741. classify_id_first,
  742. 0 as classify_id_second,
  743. classify_name_first,
  744. null as classify_name_second,
  745. type_id as report_chapter_type_id,
  746. publish_time,
  747. title
  748. FROM
  749. report_chapter
  750. WHERE
  751. report_chapter_id in (` + chapterIds + `)
  752. )) r`
  753. err = o.Raw(sql).QueryRow(&total)
  754. return
  755. }
  756. // GetPageReportList 分页获取报告列表
  757. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  758. o := orm.NewOrmUsingDB("rddp")
  759. sql := `SELECT * FROM report WHERE 1=1 `
  760. sql += condition
  761. sql += ` ORDER BY modify_time DESC`
  762. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  763. err = o.Raw(totalSql, pars).QueryRow(&total)
  764. if err != nil {
  765. return
  766. }
  767. sql += ` LIMIT ?,? `
  768. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  769. return
  770. }
  771. // SunCodeReq 获取太阳码请求体
  772. type SunCodeReq struct {
  773. CodePage string `json:"CodePage" description:"太阳码page"`
  774. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  775. }
  776. // YbPcSuncode 活动海报表
  777. type YbPcSuncode struct {
  778. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  779. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  780. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  781. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  782. SuncodeURL string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  783. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  784. }
  785. // GetYbPcSunCode 获取太阳码
  786. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  787. o := orm.NewOrmUsingDB("default")
  788. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  789. err = o.Raw(sql, scene, page).QueryRow(&item)
  790. return
  791. }
  792. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  793. o := orm.NewOrmUsingDB("default")
  794. _, err = o.Insert(item)
  795. return
  796. }
  797. // YbSuncodePars 小程序太阳码scene参数
  798. type YbSuncodePars struct {
  799. ID uint32 `orm:"column(id);pk" `
  800. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  801. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  802. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  803. }
  804. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  805. o := orm.NewOrmUsingDB("default")
  806. _, err = o.Insert(item)
  807. return
  808. }
  809. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  810. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  811. o := orm.NewOrmUsingDB("rddp")
  812. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  813. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  814. return
  815. }
  816. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  817. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  818. o := orm.NewOrmUsingDB("rddp")
  819. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  820. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  821. return
  822. }
  823. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  824. func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  825. o := orm.NewOrmUsingDB("rddp")
  826. sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  827. _, err = o.Raw(sql, classifyName, newClassifyId, classifyId).Exec()
  828. return
  829. }
  830. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  831. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  832. sql := `SELECT
  833. r.id,
  834. r.content,
  835. r.content_sub
  836. FROM
  837. report AS r
  838. JOIN ppt_v2 AS p ON r.id = p.report_id
  839. WHERE
  840. p.report_id > 0 AND r.content_sub = ""`
  841. _, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  842. return
  843. }
  844. // ModifyReportAuthor 更改报告作者
  845. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  846. //产品权限
  847. oRddp := orm.NewOrmUsingDB("rddp")
  848. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  849. if condition != "" {
  850. sql += condition
  851. }
  852. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  853. return
  854. }
  855. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  856. o := orm.NewOrmUsingDB("rddp")
  857. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  858. _, err = o.Raw(sql1, reportId).Exec()
  859. if err != nil {
  860. return
  861. }
  862. //修改音频标题
  863. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  864. _, err = o.Raw(sql2, reportId).Exec()
  865. return
  866. }
  867. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  868. o := orm.NewOrmUsingDB("rddp")
  869. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  870. _, err = o.Raw(sql1, reportId).Exec()
  871. if err != nil {
  872. return
  873. }
  874. //修改音频标题
  875. sql2 := ` UPDATE report_chapter SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE report_id = ? and (video_name !="" and video_name is not null)`
  876. _, err = o.Raw(sql2, reportId).Exec()
  877. return
  878. }
  879. // MarkEditReport 标记编辑英文研报的请求数据
  880. type MarkEditReport struct {
  881. ReportId int `description:"研报id"`
  882. Status int `description:"标记状态,1:编辑中,2:编辑完成"`
  883. }
  884. type MarkReportResp struct {
  885. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  886. Msg string `description:"提示信息"`
  887. Editor string `description:"编辑者姓名"`
  888. }
  889. type MarkReportItem struct {
  890. AdminId int `description:"编辑者ID"`
  891. Editor string `description:"编辑者姓名"`
  892. ReportClassifyNameFirst string
  893. }
  894. // GetReportByCondition 获取报告
  895. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  896. o := orm.NewOrmUsingDB("rddp")
  897. fields := `*`
  898. if len(fieldArr) > 0 {
  899. fields = strings.Join(fieldArr, ",")
  900. }
  901. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  902. sql += condition
  903. order := ` ORDER BY modify_time DESC`
  904. if orderRule != `` {
  905. order = orderRule
  906. }
  907. sql += order
  908. if isPage {
  909. sql += ` LIMIT ?,?`
  910. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  911. } else {
  912. _, err = o.Raw(sql, pars).QueryRows(&items)
  913. }
  914. return
  915. }
  916. // ModifyReportMsgIsSendV2 更新报告消息状态
  917. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  918. o := orm.NewOrmUsingDB("rddp")
  919. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  920. _, err = o.Raw(sql, reportId).Exec()
  921. return
  922. }
  923. // SetPrePublishReportById 设置定时发布
  924. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  925. o := orm.NewOrmUsingDB("rddp")
  926. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  927. _, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  928. return
  929. }