report.go 36 KB

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