report.go 35 KB

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