report.go 31 KB

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