report.go 36 KB

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