report.go 41 KB

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