report.go 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  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. ReportUrl string `description:"报告Url"`
  279. }
  280. type AddResp struct {
  281. ReportId int64 `description:"报告id"`
  282. ReportCode string `description:"报告code"`
  283. }
  284. func AddReport(item *Report) (lastId int64, err error) {
  285. o := orm.NewOrmUsingDB("rddp")
  286. lastId, err = o.Insert(item)
  287. return
  288. }
  289. type EditReq struct {
  290. ReportId int64 `description:"报告id"`
  291. ClassifyIdFirst int `description:"一级分类id"`
  292. ClassifyNameFirst string `description:"一级分类名称"`
  293. ClassifyIdSecond int `description:"二级分类id"`
  294. ClassifyNameSecond string `description:"二级分类名称"`
  295. Title string `description:"标题"`
  296. Abstract string `description:"摘要"`
  297. Author string `description:"作者"`
  298. Frequency string `description:"频度"`
  299. State int `description:"状态:1:未发布,2:已发布"`
  300. Content string `description:"内容"`
  301. CreateTime string `description:"创建时间"`
  302. }
  303. type EditResp struct {
  304. ReportId int64 `description:"报告id"`
  305. ReportCode string `description:"报告code"`
  306. }
  307. func EditReport(item *Report, reportId int64) (err error) {
  308. o := orm.NewOrmUsingDB("rddp")
  309. sql := `UPDATE report
  310. SET
  311. classify_id_first =?,
  312. classify_name_first = ?,
  313. classify_id_second = ?,
  314. classify_name_second = ?,
  315. title = ?,
  316. abstract = ?,
  317. author = ?,
  318. frequency = ?,
  319. state = ?,
  320. content = ?,
  321. content_sub = ?,
  322. stage =?,
  323. create_time = ?,
  324. modify_time = ?
  325. WHERE id = ? `
  326. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  327. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec()
  328. return
  329. }
  330. type ReportDetailReq struct {
  331. ReportId int `description:"报告id"`
  332. }
  333. type ClassifyIdDetailReq struct {
  334. ClassifyIdFirst int `description:"报告一级分类id"`
  335. ClassifyIdSecond int `description:"报告二级分类id"`
  336. }
  337. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  338. o := orm.NewOrmUsingDB("rddp")
  339. sql := ` SELECT * FROM report WHERE 1=1 `
  340. if classifyIdSecond > 0 {
  341. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  342. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  343. } else {
  344. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  345. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  346. }
  347. return
  348. }
  349. type SendTemplateMsgReq struct {
  350. ReportId int `description:"报告id"`
  351. }
  352. func ModifyReportMsgIsSend(reportId int) (err error) {
  353. o := orm.NewOrmUsingDB("rddp")
  354. report, err := GetReportById(reportId)
  355. if err != nil {
  356. return
  357. }
  358. if report.MsgIsSend == 0 {
  359. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  360. _, err = o.Raw(sql, reportId).Exec()
  361. }
  362. return
  363. }
  364. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  365. o := orm.NewOrmUsingDB("rddp")
  366. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  367. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  368. return
  369. }
  370. type ReportItem struct {
  371. Id int `orm:"column(id)" description:"报告Id"`
  372. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  373. ClassifyIdFirst int `description:"一级分类id"`
  374. ClassifyNameFirst string `description:"一级分类名称"`
  375. ClassifyIdSecond int `description:"二级分类id"`
  376. ClassifyNameSecond string `description:"二级分类名称"`
  377. Title string `description:"标题"`
  378. Abstract string `description:"摘要"`
  379. Author string `description:"作者"`
  380. Frequency string `description:"频度"`
  381. CreateTime time.Time `description:"创建时间"`
  382. ModifyTime time.Time `description:"修改时间"`
  383. State int `description:"1:未发布,2:已发布"`
  384. PublishTime time.Time `description:"发布时间"`
  385. Stage int `description:"期数"`
  386. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  387. Content string `description:"内容"`
  388. VideoUrl string `description:"音频文件URL"`
  389. VideoName string `description:"音频文件名称"`
  390. VideoPlaySeconds string `description:"音频播放时长"`
  391. ContentSub string `description:"内容前两个章节"`
  392. }
  393. func GetReportItemById(reportId int) (item *ReportItem, err error) {
  394. o := orm.NewOrmUsingDB("rddp")
  395. sql := `SELECT * FROM report WHERE id=?`
  396. err = o.Raw(sql, reportId).QueryRow(&item)
  397. return
  398. }
  399. type SaveReportContent struct {
  400. Content string `description:"内容"`
  401. ReportId int `description:"报告id"`
  402. NoChange int `description:"内容是否未改变:1:内容未改变"`
  403. }
  404. func EditReportContent(reportId int, content, contentSub string) (err error) {
  405. o := orm.NewOrmUsingDB("rddp")
  406. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  407. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  408. return
  409. }
  410. func AddReportSaveLog(reportId, adminId int, content, contentSub, adminName string) (err error) {
  411. o := orm.NewOrmUsingDB("rddp")
  412. sql := ` INSERT INTO report_save_log(report_id, content,content_sub,admin_id,admin_name) VALUES (?,?,?,?,?) `
  413. _, err = o.Raw(sql, reportId, content, contentSub, adminId, adminName).Exec()
  414. return
  415. }
  416. func MultiAddReportChaptersSaveLog(items []*ReportChapter, adminId int, adminRealName string) (err error) {
  417. o := orm.NewOrmUsingDB("rddp")
  418. p, err := o.Raw(`INSERT INTO report_save_log(report_id, report_chapter_id, content, content_sub, admin_id, admin_name) VALUES (?,?,?,?,?,?)`).Prepare()
  419. if err != nil {
  420. return
  421. }
  422. defer func() {
  423. _ = p.Close()
  424. }()
  425. for _, v := range items {
  426. _, err = p.Exec(v.ReportId, v.ReportChapterId, v.Content, v.ContentSub, adminId, adminRealName)
  427. if err != nil {
  428. return
  429. }
  430. }
  431. return
  432. }
  433. type SaveReportContentResp struct {
  434. ReportId int `description:"报告id"`
  435. }
  436. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  437. o := orm.NewOrmUsingDB("rddp")
  438. sql := `UPDATE report SET report_code=? WHERE id=? `
  439. _, err = o.Raw(sql, reportCode, reportId).Exec()
  440. return
  441. }
  442. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  443. o := orm.NewOrmUsingDB("rddp")
  444. if item.ThsMsgIsSend == 0 {
  445. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  446. _, err = o.Raw(sql, item.Id).Exec()
  447. }
  448. return
  449. }
  450. type ThsSendTemplateMsgReq struct {
  451. ReportId []int `description:"报告id"`
  452. }
  453. type PublishDayWeekReportReq struct {
  454. ReportId int `description:"报告ID"`
  455. }
  456. // SaveDayWeekReportReq 新增晨报周报请求体
  457. type SaveDayWeekReportReq struct {
  458. ReportId int `description:"报告ID"`
  459. Title string `description:"标题"`
  460. ReportType string `description:"一级分类ID"`
  461. Author string `description:"作者"`
  462. CreateTime string `description:"创建时间"`
  463. }
  464. // GetDayWeekReportStage 获取晨报周报期数
  465. func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  466. o := orm.NewOrmUsingDB("rddp")
  467. sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  468. o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  469. return
  470. }
  471. // AddReportAndChapter 新增报告及章节
  472. func AddReportAndChapter(reportItem *Report, chapterItemList []*ReportChapter) (reportId int64, err error) {
  473. o := orm.NewOrmUsingDB("rddp")
  474. to, err := o.Begin()
  475. if err != nil {
  476. return
  477. }
  478. defer func() {
  479. if err != nil {
  480. _ = to.Rollback()
  481. } else {
  482. _ = to.Commit()
  483. }
  484. }()
  485. if reportId, err = to.Insert(reportItem); err != nil {
  486. return
  487. }
  488. if len(chapterItemList) > 0 {
  489. for _, chapterItem := range chapterItemList {
  490. chapterItem.ReportId = int(reportId)
  491. cpId, tmpErr := to.Insert(chapterItem)
  492. if tmpErr != nil {
  493. return
  494. }
  495. chapterItem.ReportChapterId = int(cpId)
  496. }
  497. }
  498. return
  499. }
  500. // GetReportByReportId 主键获取报告
  501. func GetReportByReportId(reportId int) (item *Report, err error) {
  502. o := orm.NewOrmUsingDB("rddp")
  503. sql := `SELECT * FROM report WHERE id = ?`
  504. err = o.Raw(sql, reportId).QueryRow(&item)
  505. return
  506. }
  507. // GetReportByOldReportId 根据老报告id主键获取报告
  508. func GetReportByOldReportId(reportId int) (item *Report, err error) {
  509. o := orm.NewOrmUsingDB("rddp")
  510. sql := `SELECT * FROM report WHERE old_report_id = ?`
  511. err = o.Raw(sql, reportId).QueryRow(&item)
  512. return
  513. }
  514. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  515. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  516. o := orm.NewOrmUsingDB("rddp")
  517. to, err := o.Begin()
  518. if err != nil {
  519. return
  520. }
  521. defer func() {
  522. if err != nil {
  523. _ = to.Rollback()
  524. } else {
  525. _ = to.Commit()
  526. }
  527. }()
  528. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  529. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  530. return
  531. }
  532. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  533. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  534. return
  535. }
  536. return
  537. }
  538. // UpdateReport 更新报告
  539. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  540. o := orm.NewOrmUsingDB("rddp")
  541. _, err = o.Update(reportInfo, cols...)
  542. return
  543. }
  544. // 晨周报详情
  545. type ReportDetailView struct {
  546. *ReportDetail
  547. ChapterList []*ReportChapter
  548. }
  549. func GetUnPublishDayReport(startTime time.Time, endTime time.Time) (item *Report, err error) {
  550. o := orm.NewOrmUsingDB("rddp")
  551. sql := ` SELECT
  552. *
  553. FROM
  554. report AS a
  555. WHERE
  556. a.has_chapter = 1
  557. AND a.chapter_type = "day"
  558. AND a.state = 1
  559. AND (
  560. a.create_time BETWEEN ? AND ?
  561. )
  562. ORDER BY
  563. a.create_time DESC
  564. LIMIT 1 `
  565. err = o.Raw(sql, startTime, endTime).QueryRow(&item)
  566. return
  567. }
  568. type ElasticReportDetail struct {
  569. ReportId int `description:"报告ID"`
  570. ReportChapterId int `description:"报告章节ID"`
  571. Title string `description:"标题"`
  572. Abstract string `description:"摘要"`
  573. BodyContent string `description:"内容"`
  574. PublishTime string `description:"发布时间"`
  575. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  576. Author string `description:"作者"`
  577. ClassifyIdFirst int `description:"一级分类ID"`
  578. ClassifyNameFirst string `description:"一级分类名称"`
  579. ClassifyIdSecond int `description:"二级分类ID"`
  580. ClassifyNameSecond string `description:"二级分类名称"`
  581. Categories string `description:"关联的品种名称(包括品种别名)"`
  582. StageStr string `description:"报告期数"`
  583. }
  584. // GetLastPublishedDayWeekReport 获取上一篇已发布的晨周报
  585. func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  586. o := orm.NewOrmUsingDB("rddp")
  587. sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  588. err = o.Raw(sql, chapterType).QueryRow(&item)
  589. return
  590. }
  591. // GetNewReportExist
  592. func GetNewReportExist(oldReportId int) (item *Report, err error) {
  593. o := orm.NewOrmUsingDB("rddp")
  594. sql := ` SELECT id FROM report WHERE old_report_id = ? LIMIT 1 `
  595. err = o.Raw(sql, oldReportId).QueryRow(&item)
  596. return
  597. }
  598. // PublishReportAndChapter 发布报告及章节
  599. func PublishReportAndChapter(reportInfo *Report, publishIds, unPublishIds []int, isPublishReport bool, cols []string) (err error) {
  600. o := orm.NewOrmUsingDB("rddp")
  601. to, err := o.Begin()
  602. if err != nil {
  603. return
  604. }
  605. defer func() {
  606. if err != nil {
  607. _ = to.Rollback()
  608. } else {
  609. _ = to.Commit()
  610. }
  611. }()
  612. // 更新报告
  613. if isPublishReport {
  614. if _, err = to.Update(reportInfo, cols...); err != nil {
  615. return
  616. }
  617. }
  618. // 发布章节
  619. if len(publishIds) > 0 {
  620. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  621. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  622. }
  623. if len(unPublishIds) > 0 {
  624. 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)) + `) `
  625. _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  626. }
  627. return
  628. }
  629. func GetSyncEmptyVideoReport() (list []*Report, err error) {
  630. o := orm.NewOrmUsingDB("rddp")
  631. sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  632. UNION ALL
  633. SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  634. _, err = o.Raw(sql).QueryRows(&list)
  635. return
  636. }
  637. // PublishReportById 发布报告
  638. func PublishReportById(reportId int, publishTime time.Time) (err error) {
  639. o := orm.NewOrmUsingDB("rddp")
  640. sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
  641. _, err = o.Raw(sql, publishTime, reportId).Exec()
  642. return
  643. }
  644. // ResetReportById 重置报告状态
  645. func ResetReportById(reportId, state int) (err error) {
  646. o := orm.NewOrmUsingDB("rddp")
  647. sql := `UPDATE report SET state = ?, pre_publish_time = null, pre_msg_send = 0, modify_time = NOW() WHERE id = ?`
  648. _, err = o.Raw(sql, state, reportId).Exec()
  649. return
  650. }
  651. // GetCommentReportByReportId 查询有留言的报告列表
  652. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  653. o := orm.NewOrmUsingDB("rddp")
  654. sql := `SELECT
  655. id,
  656. create_time,
  657. title,
  658. classify_name_first,
  659. classify_id_first,
  660. classify_name_second,
  661. classify_id_second,
  662. state,
  663. IF
  664. ( publish_time, publish_time, create_time ) AS publish_time
  665. FROM
  666. report
  667. WHERE
  668. 1=1
  669. `
  670. if condition != "" {
  671. sql += condition
  672. }
  673. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  674. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  675. return
  676. }
  677. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  678. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  679. o := orm.NewOrmUsingDB("rddp")
  680. sql := `SELECT
  681. id,
  682. create_time,
  683. title,
  684. classify_name_first,
  685. classify_id_first,
  686. classify_name_second,
  687. classify_id_second,
  688. state,
  689. IF
  690. ( publish_time, publish_time, create_time ) AS publish_time
  691. FROM
  692. report
  693. WHERE
  694. 1=1
  695. `
  696. if condition != "" {
  697. sql += condition
  698. }
  699. if orderBy == `` {
  700. sql += ` ORDER BY publish_time DESC , title ASC `
  701. } else {
  702. sql += orderBy
  703. }
  704. sql += ` LIMIT ?,? `
  705. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  706. return
  707. }
  708. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  709. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  710. o := orm.NewOrmUsingDB("rddp")
  711. sql := `SELECT count(*)
  712. FROM report WHERE 1=1`
  713. if condition != "" {
  714. sql += condition
  715. }
  716. err = o.Raw(sql, pars).QueryRow(&total)
  717. return
  718. }
  719. // 点赞相关的报告列表
  720. type LikeReportItem struct {
  721. ReportId int `description:"报告Id"`
  722. ReportChapterId int `description:"报告章节Id"`
  723. ClassifyIdFirst int `description:"一级分类id"`
  724. ClassifyNameFirst string `description:"一级分类名称"`
  725. ClassifyIdSecond int `description:"二级分类id"`
  726. ClassifyNameSecond string `description:"二级分类名称"`
  727. ReportChapterTypeId int `description:"章节类型"`
  728. ReportChapterTypeName string `description:"品种名称"`
  729. PublishTime time.Time `description:"发布时间" `
  730. Title string `description:"标题"`
  731. }
  732. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  733. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  734. o := orm.NewOrmUsingDB("rddp")
  735. sql := `( SELECT
  736. id AS report_id,
  737. 0 AS report_chapter_id,
  738. classify_id_first,
  739. classify_id_second,
  740. classify_name_first,
  741. classify_name_second,
  742. 0 as report_chapter_type_id,
  743. "" as report_chapter_type_name,
  744. publish_time,
  745. title
  746. FROM
  747. report
  748. WHERE
  749. classify_name_first != "晨报"
  750. AND classify_name_first != "周报"
  751. AND id in (` + reportIds + `)
  752. )
  753. UNION
  754. ( SELECT
  755. report_id,
  756. report_chapter_id,
  757. classify_id_first,
  758. 0 as classify_id_second,
  759. classify_name_first,
  760. null as classify_name_second,
  761. type_id as report_chapter_type_id,
  762. type_name as report_chapter_type_name,
  763. publish_time,
  764. title
  765. FROM
  766. report_chapter
  767. WHERE
  768. report_chapter_id in (` + chapterIds + `)
  769. )`
  770. if orderStr != "" {
  771. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  772. } else {
  773. sql += ` ORDER BY publish_time DESC, report_id Desc`
  774. }
  775. sql += ` LIMIT ?,?`
  776. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  777. return
  778. }
  779. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  780. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  781. o := orm.NewOrmUsingDB("rddp")
  782. sql := `select count(*) from (( SELECT
  783. id AS report_id,
  784. 0 AS report_chapter_id,
  785. classify_id_first,
  786. classify_id_second,
  787. classify_name_first,
  788. classify_name_second,
  789. 0 as report_chapter_type_id,
  790. publish_time,
  791. title
  792. FROM
  793. report
  794. WHERE
  795. classify_name_first != "晨报"
  796. AND classify_name_first != "周报"
  797. AND id in (` + reportIds + `)
  798. )
  799. UNION
  800. ( SELECT
  801. report_id,
  802. report_chapter_id,
  803. classify_id_first,
  804. 0 as classify_id_second,
  805. classify_name_first,
  806. null as classify_name_second,
  807. type_id as report_chapter_type_id,
  808. publish_time,
  809. title
  810. FROM
  811. report_chapter
  812. WHERE
  813. report_chapter_id in (` + chapterIds + `)
  814. )) r`
  815. err = o.Raw(sql).QueryRow(&total)
  816. return
  817. }
  818. // GetPageReportList 分页获取报告列表
  819. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  820. o := orm.NewOrmUsingDB("rddp")
  821. sql := `SELECT * FROM report WHERE 1=1 `
  822. sql += condition
  823. sql += ` ORDER BY modify_time DESC`
  824. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  825. err = o.Raw(totalSql, pars).QueryRow(&total)
  826. if err != nil {
  827. return
  828. }
  829. sql += ` LIMIT ?,? `
  830. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  831. return
  832. }
  833. // SunCodeReq 获取太阳码请求体
  834. type SunCodeReq struct {
  835. CodePage string `json:"CodePage" description:"太阳码page"`
  836. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  837. }
  838. // YbPcSuncode 活动海报表
  839. type YbPcSuncode struct {
  840. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  841. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  842. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  843. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  844. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  845. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  846. }
  847. // GetYbPcSunCode 获取太阳码
  848. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  849. o := orm.NewOrmUsingDB("weekly")
  850. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  851. err = o.Raw(sql, scene, page).QueryRow(&item)
  852. return
  853. }
  854. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  855. o := orm.NewOrmUsingDB("weekly")
  856. _, err = o.Insert(item)
  857. return
  858. }
  859. // YbSuncodePars 小程序太阳码scene参数
  860. type YbSuncodePars struct {
  861. ID uint32 `orm:"column(id);pk" `
  862. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  863. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  864. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  865. }
  866. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  867. o := orm.NewOrmUsingDB("weekly")
  868. _, err = o.Insert(item)
  869. return
  870. }
  871. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  872. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  873. o := orm.NewOrmUsingDB("rddp")
  874. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  875. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  876. return
  877. }
  878. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  879. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  880. o := orm.NewOrmUsingDB("rddp")
  881. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  882. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  883. return
  884. }
  885. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  886. func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  887. o := orm.NewOrmUsingDB("rddp")
  888. sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  889. _, err = o.Raw(sql, classifyName, newClassifyId, classifyId).Exec()
  890. return
  891. }
  892. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  893. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  894. sql := `SELECT
  895. r.id,
  896. r.content,
  897. r.content_sub
  898. FROM
  899. report AS r
  900. JOIN ppt_v2 AS p ON r.id = p.report_id
  901. WHERE
  902. p.report_id > 0 AND r.content_sub = ""`
  903. _, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  904. return
  905. }
  906. // ModifyReportAuthor 更改报告作者
  907. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  908. //产品权限
  909. oRddp := orm.NewOrmUsingDB("rddp")
  910. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  911. if condition != "" {
  912. sql += condition
  913. }
  914. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  915. return
  916. }
  917. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  918. o := orm.NewOrmUsingDB("rddp")
  919. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  920. _, err = o.Raw(sql1, reportId).Exec()
  921. if err != nil {
  922. return
  923. }
  924. //修改音频标题
  925. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  926. _, err = o.Raw(sql2, reportId).Exec()
  927. return
  928. }
  929. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  930. o := orm.NewOrmUsingDB("rddp")
  931. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  932. _, err = o.Raw(sql1, reportId).Exec()
  933. if err != nil {
  934. return
  935. }
  936. //修改音频标题
  937. 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)`
  938. _, err = o.Raw(sql2, reportId).Exec()
  939. return
  940. }
  941. // MarkEditReport 标记编辑英文研报的请求数据
  942. type MarkEditReport struct {
  943. ReportId int `description:"研报id"`
  944. Status int `description:"标记状态,1:编辑中,2:编辑完成"`
  945. }
  946. type MarkReportResp struct {
  947. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  948. Msg string `description:"提示信息"`
  949. Editor string `description:"编辑者姓名"`
  950. }
  951. type MarkReportItem struct {
  952. AdminId int `description:"编辑者ID"`
  953. Editor string `description:"编辑者姓名"`
  954. ReportClassifyNameFirst string
  955. }
  956. // GetReportByCondition 获取报告
  957. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  958. o := orm.NewOrmUsingDB("rddp")
  959. fields := `*`
  960. if len(fieldArr) > 0 {
  961. fields = strings.Join(fieldArr, ",")
  962. }
  963. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  964. sql += condition
  965. order := ` ORDER BY modify_time DESC`
  966. if orderRule != `` {
  967. order = orderRule
  968. }
  969. sql += order
  970. if isPage {
  971. sql += ` LIMIT ?,?`
  972. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  973. } else {
  974. _, err = o.Raw(sql, pars).QueryRows(&items)
  975. }
  976. return
  977. }
  978. // ModifyReportMsgIsSendV2 更新报告消息状态
  979. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  980. o := orm.NewOrmUsingDB("rddp")
  981. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  982. _, err = o.Raw(sql, reportId).Exec()
  983. return
  984. }
  985. // SetPrePublishReportById 设置定时发布
  986. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  987. o := orm.NewOrmUsingDB("rddp")
  988. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  989. _, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  990. return
  991. }
  992. // ReportSubmitApproveReq 提交审批请求体
  993. type ReportSubmitApproveReq struct {
  994. ReportId int `description:"报告ID"`
  995. }
  996. // ReportCancelApproveReq 撤回审批请求体
  997. type ReportCancelApproveReq struct {
  998. ReportId int `description:"报告ID"`
  999. }
  1000. func (m *Report) GetItemById(id int) (item *Report, err error) {
  1001. o := orm.NewOrmUsingDB("rddp")
  1002. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  1003. err = o.Raw(sql, id).QueryRow(&item)
  1004. return
  1005. }
  1006. // GetReportStateCount 获取指定状态的报告数量
  1007. func GetReportStateCount(state int) (count int, err error) {
  1008. o := orm.NewOrmUsingDB("rddp")
  1009. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  1010. err = o.Raw(sql, state).QueryRow(&count)
  1011. return
  1012. }
  1013. // UpdateReportsStateByCond 批量更新报告状态
  1014. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, oldState, newState int) (err error) {
  1015. o := orm.NewOrmUsingDB("rddp")
  1016. cond := ``
  1017. if classifyFirstId > 0 {
  1018. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  1019. }
  1020. if classifySecondId > 0 {
  1021. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  1022. }
  1023. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  1024. _, err = o.Raw(sql, newState, oldState).Exec()
  1025. return
  1026. }
  1027. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  1028. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  1029. if len(secondIds) <= 0 {
  1030. return
  1031. }
  1032. o := orm.NewOrmUsingDB("rddp")
  1033. // (有审批流的)未发布->待提交
  1034. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1035. _, err = o.Raw(sql, newState, oldState, secondIds).Exec()
  1036. if err != nil {
  1037. return
  1038. }
  1039. // (无审批流的)待提交->未发布
  1040. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1041. _, err = o.Raw(sql, oldState, newState, secondIds).Exec()
  1042. return
  1043. }
  1044. // GetReportPdfUrlReq 获取报告pdf地址请求体
  1045. type GetReportPdfUrlReq struct {
  1046. ReportUrl string `description:"报告Url"`
  1047. ReportCode string `description:"报告Code"`
  1048. Type int `description:"类型 1-pdf 2-图片"`
  1049. }
  1050. func ModifyReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  1051. o := orm.NewOrmUsingDB("rddp")
  1052. sql := `UPDATE report SET detail_pdf_url=? WHERE id=? `
  1053. _, err = o.Raw(sql, detailPdfUrl, reportId).Exec()
  1054. return
  1055. }
  1056. func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
  1057. o := orm.NewOrmUsingDB("rddp")
  1058. sql := `UPDATE report SET detail_img_url=? WHERE id=? `
  1059. _, err = o.Raw(sql, detailImgUrl, reportId).Exec()
  1060. return
  1061. }