report.go 37 KB

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