report.go 39 KB

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