report.go 40 KB

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