report.go 41 KB

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