report.go 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  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. }
  580. // GetLastPublishedDayWeekReport 获取上一篇已发布的晨周报
  581. func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  582. o := orm.NewOrmUsingDB("rddp")
  583. sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  584. err = o.Raw(sql, chapterType).QueryRow(&item)
  585. return
  586. }
  587. // GetNewReportExist
  588. func GetNewReportExist(oldReportId int) (item *Report, err error) {
  589. o := orm.NewOrmUsingDB("rddp")
  590. sql := ` SELECT id FROM report WHERE old_report_id = ? LIMIT 1 `
  591. err = o.Raw(sql, oldReportId).QueryRow(&item)
  592. return
  593. }
  594. // PublishReportAndChapter 发布报告及章节
  595. func PublishReportAndChapter(reportInfo *Report, publishIds, unPublishIds []int, isPublishReport bool, cols []string) (err error) {
  596. o := orm.NewOrmUsingDB("rddp")
  597. to, err := o.Begin()
  598. if err != nil {
  599. return
  600. }
  601. defer func() {
  602. if err != nil {
  603. _ = to.Rollback()
  604. } else {
  605. _ = to.Commit()
  606. }
  607. }()
  608. // 更新报告
  609. if isPublishReport {
  610. if _, err = to.Update(reportInfo, cols...); err != nil {
  611. return
  612. }
  613. }
  614. // 发布章节
  615. if len(publishIds) > 0 {
  616. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  617. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  618. }
  619. if len(unPublishIds) > 0 {
  620. 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)) + `) `
  621. _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  622. }
  623. return
  624. }
  625. func GetSyncEmptyVideoReport() (list []*Report, err error) {
  626. o := orm.NewOrmUsingDB("rddp")
  627. sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  628. UNION ALL
  629. SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  630. _, err = o.Raw(sql).QueryRows(&list)
  631. return
  632. }
  633. // PublishReportById 发布报告
  634. func PublishReportById(reportId int, publishTime time.Time) (err error) {
  635. o := orm.NewOrmUsingDB("rddp")
  636. sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
  637. _, err = o.Raw(sql, publishTime, reportId).Exec()
  638. return
  639. }
  640. // ResetReportById 重置报告状态
  641. func ResetReportById(reportId, state int) (err error) {
  642. o := orm.NewOrmUsingDB("rddp")
  643. sql := `UPDATE report SET state = ?, pre_publish_time = null, pre_msg_send = 0, modify_time = NOW() WHERE id = ?`
  644. _, err = o.Raw(sql, state, reportId).Exec()
  645. return
  646. }
  647. // GetCommentReportByReportId 查询有留言的报告列表
  648. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  649. o := orm.NewOrmUsingDB("rddp")
  650. sql := `SELECT
  651. id,
  652. create_time,
  653. title,
  654. classify_name_first,
  655. classify_id_first,
  656. classify_name_second,
  657. classify_id_second,
  658. state,
  659. IF
  660. ( publish_time, publish_time, create_time ) AS publish_time
  661. FROM
  662. report
  663. WHERE
  664. 1=1
  665. `
  666. if condition != "" {
  667. sql += condition
  668. }
  669. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  670. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  671. return
  672. }
  673. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  674. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  675. o := orm.NewOrmUsingDB("rddp")
  676. sql := `SELECT
  677. id,
  678. create_time,
  679. title,
  680. classify_name_first,
  681. classify_id_first,
  682. classify_name_second,
  683. classify_id_second,
  684. state,
  685. IF
  686. ( publish_time, publish_time, create_time ) AS publish_time
  687. FROM
  688. report
  689. WHERE
  690. 1=1
  691. `
  692. if condition != "" {
  693. sql += condition
  694. }
  695. if orderBy == `` {
  696. sql += ` ORDER BY publish_time DESC , title ASC `
  697. } else {
  698. sql += orderBy
  699. }
  700. sql += ` LIMIT ?,? `
  701. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  702. return
  703. }
  704. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  705. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  706. o := orm.NewOrmUsingDB("rddp")
  707. sql := `SELECT count(*)
  708. FROM report WHERE 1=1`
  709. if condition != "" {
  710. sql += condition
  711. }
  712. err = o.Raw(sql, pars).QueryRow(&total)
  713. return
  714. }
  715. // 点赞相关的报告列表
  716. type LikeReportItem struct {
  717. ReportId int `description:"报告Id"`
  718. ReportChapterId int `description:"报告章节Id"`
  719. ClassifyIdFirst int `description:"一级分类id"`
  720. ClassifyNameFirst string `description:"一级分类名称"`
  721. ClassifyIdSecond int `description:"二级分类id"`
  722. ClassifyNameSecond string `description:"二级分类名称"`
  723. ReportChapterTypeId int `description:"章节类型"`
  724. ReportChapterTypeName string `description:"品种名称"`
  725. PublishTime time.Time `description:"发布时间" `
  726. Title string `description:"标题"`
  727. }
  728. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  729. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  730. o := orm.NewOrmUsingDB("rddp")
  731. sql := `( SELECT
  732. id AS report_id,
  733. 0 AS report_chapter_id,
  734. classify_id_first,
  735. classify_id_second,
  736. classify_name_first,
  737. classify_name_second,
  738. 0 as report_chapter_type_id,
  739. "" as report_chapter_type_name,
  740. publish_time,
  741. title
  742. FROM
  743. report
  744. WHERE
  745. classify_name_first != "晨报"
  746. AND classify_name_first != "周报"
  747. AND id in (` + reportIds + `)
  748. )
  749. UNION
  750. ( SELECT
  751. report_id,
  752. report_chapter_id,
  753. classify_id_first,
  754. 0 as classify_id_second,
  755. classify_name_first,
  756. null as classify_name_second,
  757. type_id as report_chapter_type_id,
  758. type_name as report_chapter_type_name,
  759. publish_time,
  760. title
  761. FROM
  762. report_chapter
  763. WHERE
  764. report_chapter_id in (` + chapterIds + `)
  765. )`
  766. if orderStr != "" {
  767. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  768. } else {
  769. sql += ` ORDER BY publish_time DESC, report_id Desc`
  770. }
  771. sql += ` LIMIT ?,?`
  772. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  773. return
  774. }
  775. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  776. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  777. o := orm.NewOrmUsingDB("rddp")
  778. sql := `select count(*) from (( SELECT
  779. id AS report_id,
  780. 0 AS report_chapter_id,
  781. classify_id_first,
  782. classify_id_second,
  783. classify_name_first,
  784. classify_name_second,
  785. 0 as report_chapter_type_id,
  786. publish_time,
  787. title
  788. FROM
  789. report
  790. WHERE
  791. classify_name_first != "晨报"
  792. AND classify_name_first != "周报"
  793. AND id in (` + reportIds + `)
  794. )
  795. UNION
  796. ( SELECT
  797. report_id,
  798. report_chapter_id,
  799. classify_id_first,
  800. 0 as classify_id_second,
  801. classify_name_first,
  802. null as classify_name_second,
  803. type_id as report_chapter_type_id,
  804. publish_time,
  805. title
  806. FROM
  807. report_chapter
  808. WHERE
  809. report_chapter_id in (` + chapterIds + `)
  810. )) r`
  811. err = o.Raw(sql).QueryRow(&total)
  812. return
  813. }
  814. // GetPageReportList 分页获取报告列表
  815. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  816. o := orm.NewOrmUsingDB("rddp")
  817. sql := `SELECT * FROM report WHERE 1=1 `
  818. sql += condition
  819. sql += ` ORDER BY modify_time DESC`
  820. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  821. err = o.Raw(totalSql, pars).QueryRow(&total)
  822. if err != nil {
  823. return
  824. }
  825. sql += ` LIMIT ?,? `
  826. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  827. return
  828. }
  829. // SunCodeReq 获取太阳码请求体
  830. type SunCodeReq struct {
  831. CodePage string `json:"CodePage" description:"太阳码page"`
  832. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  833. }
  834. // YbPcSuncode 活动海报表
  835. type YbPcSuncode struct {
  836. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  837. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  838. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  839. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  840. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  841. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  842. }
  843. // GetYbPcSunCode 获取太阳码
  844. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  845. o := orm.NewOrmUsingDB("weekly")
  846. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  847. err = o.Raw(sql, scene, page).QueryRow(&item)
  848. return
  849. }
  850. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  851. o := orm.NewOrmUsingDB("weekly")
  852. _, err = o.Insert(item)
  853. return
  854. }
  855. // YbSuncodePars 小程序太阳码scene参数
  856. type YbSuncodePars struct {
  857. ID uint32 `orm:"column(id);pk" `
  858. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  859. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  860. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  861. }
  862. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  863. o := orm.NewOrmUsingDB("weekly")
  864. _, err = o.Insert(item)
  865. return
  866. }
  867. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  868. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  869. o := orm.NewOrmUsingDB("rddp")
  870. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  871. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  872. return
  873. }
  874. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  875. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  876. o := orm.NewOrmUsingDB("rddp")
  877. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  878. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  879. return
  880. }
  881. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  882. func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  883. o := orm.NewOrmUsingDB("rddp")
  884. sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  885. _, err = o.Raw(sql, classifyName, newClassifyId, classifyId).Exec()
  886. return
  887. }
  888. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  889. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  890. sql := `SELECT
  891. r.id,
  892. r.content,
  893. r.content_sub
  894. FROM
  895. report AS r
  896. JOIN ppt_v2 AS p ON r.id = p.report_id
  897. WHERE
  898. p.report_id > 0 AND r.content_sub = ""`
  899. _, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  900. return
  901. }
  902. // ModifyReportAuthor 更改报告作者
  903. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  904. //产品权限
  905. oRddp := orm.NewOrmUsingDB("rddp")
  906. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  907. if condition != "" {
  908. sql += condition
  909. }
  910. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  911. return
  912. }
  913. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  914. o := orm.NewOrmUsingDB("rddp")
  915. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  916. _, err = o.Raw(sql1, reportId).Exec()
  917. if err != nil {
  918. return
  919. }
  920. //修改音频标题
  921. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  922. _, err = o.Raw(sql2, reportId).Exec()
  923. return
  924. }
  925. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  926. o := orm.NewOrmUsingDB("rddp")
  927. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  928. _, err = o.Raw(sql1, reportId).Exec()
  929. if err != nil {
  930. return
  931. }
  932. //修改音频标题
  933. 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)`
  934. _, err = o.Raw(sql2, reportId).Exec()
  935. return
  936. }
  937. // MarkEditReport 标记编辑英文研报的请求数据
  938. type MarkEditReport struct {
  939. ReportId int `description:"研报id"`
  940. Status int `description:"标记状态,1:编辑中,2:编辑完成"`
  941. }
  942. type MarkReportResp struct {
  943. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  944. Msg string `description:"提示信息"`
  945. Editor string `description:"编辑者姓名"`
  946. }
  947. type MarkReportItem struct {
  948. AdminId int `description:"编辑者ID"`
  949. Editor string `description:"编辑者姓名"`
  950. ReportClassifyNameFirst string
  951. }
  952. // GetReportByCondition 获取报告
  953. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  954. o := orm.NewOrmUsingDB("rddp")
  955. fields := `*`
  956. if len(fieldArr) > 0 {
  957. fields = strings.Join(fieldArr, ",")
  958. }
  959. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  960. sql += condition
  961. order := ` ORDER BY modify_time DESC`
  962. if orderRule != `` {
  963. order = orderRule
  964. }
  965. sql += order
  966. if isPage {
  967. sql += ` LIMIT ?,?`
  968. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  969. } else {
  970. _, err = o.Raw(sql, pars).QueryRows(&items)
  971. }
  972. return
  973. }
  974. // ModifyReportMsgIsSendV2 更新报告消息状态
  975. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  976. o := orm.NewOrmUsingDB("rddp")
  977. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  978. _, err = o.Raw(sql, reportId).Exec()
  979. return
  980. }
  981. // SetPrePublishReportById 设置定时发布
  982. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  983. o := orm.NewOrmUsingDB("rddp")
  984. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  985. _, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  986. return
  987. }
  988. // ReportSubmitApproveReq 提交审批请求体
  989. type ReportSubmitApproveReq struct {
  990. ReportId int `description:"报告ID"`
  991. }
  992. // ReportCancelApproveReq 撤回审批请求体
  993. type ReportCancelApproveReq struct {
  994. ReportId int `description:"报告ID"`
  995. }
  996. func (m *Report) GetItemById(id int) (item *Report, err error) {
  997. o := orm.NewOrmUsingDB("rddp")
  998. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  999. err = o.Raw(sql, id).QueryRow(&item)
  1000. return
  1001. }
  1002. // GetReportStateCount 获取指定状态的报告数量
  1003. func GetReportStateCount(state int) (count int, err error) {
  1004. o := orm.NewOrmUsingDB("rddp")
  1005. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  1006. err = o.Raw(sql, state).QueryRow(&count)
  1007. return
  1008. }
  1009. // UpdateReportsStateByCond 批量更新报告状态
  1010. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, oldState, newState int) (err error) {
  1011. o := orm.NewOrmUsingDB("rddp")
  1012. cond := ``
  1013. if classifyFirstId > 0 {
  1014. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  1015. }
  1016. if classifySecondId > 0 {
  1017. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  1018. }
  1019. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  1020. _, err = o.Raw(sql, newState, oldState).Exec()
  1021. return
  1022. }
  1023. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  1024. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  1025. if len(secondIds) <= 0 {
  1026. return
  1027. }
  1028. o := orm.NewOrmUsingDB("rddp")
  1029. // (有审批流的)未发布->待提交
  1030. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1031. _, err = o.Raw(sql, newState, oldState, secondIds).Exec()
  1032. if err != nil {
  1033. return
  1034. }
  1035. // (无审批流的)待提交->未发布
  1036. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1037. _, err = o.Raw(sql, oldState, newState, secondIds).Exec()
  1038. return
  1039. }