report.go 40 KB

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