report.go 42 KB

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