report.go 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  1. package models
  2. import (
  3. "errors"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. "strings"
  9. "time"
  10. )
  11. // 报告状态
  12. const (
  13. ReportStateUnpublished = 1 // 未发布
  14. ReportStatePublished = 2 // 已发布
  15. ReportStateWaitSubmit = 3 // 待提交
  16. ReportStateWaitApprove = 4 // 审批中
  17. ReportStateRefused = 5 // 已驳回
  18. ReportStatePass = 6 // 已通过
  19. )
  20. // 报告操作
  21. const (
  22. ReportOperateAdd = 1 // 新增报告
  23. ReportOperateEdit = 2 // 编辑报告
  24. ReportOperatePublish = 3 // 发布报告
  25. ReportOperateCancelPublish = 4 // 取消发布报告
  26. ReportOperateSubmitApprove = 5 // 提交审批
  27. ReportOperateCancelApprove = 6 // 撤回审批
  28. )
  29. type Report struct {
  30. Id int `orm:"column(id)" description:"报告Id"`
  31. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  32. ClassifyIdFirst int `description:"一级分类id"`
  33. ClassifyNameFirst string `description:"一级分类名称"`
  34. ClassifyIdSecond int `description:"二级分类id"`
  35. ClassifyNameSecond string `description:"二级分类名称"`
  36. Title string `description:"标题"`
  37. Abstract string `description:"摘要"`
  38. Author string `description:"作者"`
  39. Frequency string `description:"频度"`
  40. CreateTime string `description:"创建时间"`
  41. ModifyTime time.Time `description:"修改时间"`
  42. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  43. PublishTime time.Time `description:"发布时间"`
  44. Stage int `description:"期数"`
  45. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  46. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  47. Content string `description:"内容"`
  48. VideoUrl string `description:"音频文件URL"`
  49. VideoName string `description:"音频文件名称"`
  50. VideoPlaySeconds string `description:"音频播放时长"`
  51. VideoSize string `description:"音频文件大小,单位M"`
  52. ContentSub string `description:"内容前两个章节"`
  53. ReportCode string `description:"报告唯一编码"`
  54. ReportVersion int `description:"1:旧版,2:新版"`
  55. HasChapter int `description:"是否有章节 0-否 1-是"`
  56. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  57. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  58. MsgSendTime time.Time `description:"模版消息发送时间"`
  59. AdminId int `description:"创建者账号"`
  60. AdminRealName string `description:"创建者姓名"`
  61. ApproveTime time.Time `description:"审批时间"`
  62. ApproveId int `description:"审批ID"`
  63. DetailImgUrl string `description:"报告详情长图地址"`
  64. DetailPdfUrl string `description:"报告详情PDF地址"`
  65. ContentStruct string `description:"内容组件"`
  66. LastModifyAdminId int `description:"最后更新人ID"`
  67. LastModifyAdminName string `description:"最后更新人姓名"`
  68. ContentModifyTime time.Time `description:"内容更新时间"`
  69. Pv int `description:"pv"`
  70. Uv int `description:"uv"`
  71. HeadImg string `description:"报告头图地址"`
  72. EndImg string `description:"报告尾图地址"`
  73. CanvasColor string `description:"画布颜色"`
  74. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  75. HeadResourceId int `description:"版头资源ID"`
  76. EndResourceId int `description:"版尾资源ID"`
  77. ClassifyIdThird int `description:"三级分类id"`
  78. ClassifyNameThird string `description:"三级分类名称"`
  79. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  80. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  81. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  82. ReportCreateTime time.Time `description:"报告时间创建时间"`
  83. InheritReportId int `description:"待继承的报告ID"`
  84. }
  85. type ReportList struct {
  86. Id int `description:"报告Id"`
  87. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  88. ClassifyIdFirst int `description:"一级分类id"`
  89. ClassifyNameFirst string `description:"一级分类名称"`
  90. ClassifyIdSecond int `description:"二级分类id"`
  91. ClassifyNameSecond string `description:"二级分类名称"`
  92. Title string `description:"标题"`
  93. Abstract string `description:"摘要"`
  94. Author string `description:"作者"`
  95. Frequency string `description:"频度"`
  96. CreateTime string `description:"创建时间"`
  97. ModifyTime time.Time `description:"修改时间"`
  98. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  99. PublishTime string `description:"发布时间"`
  100. PrePublishTime string `description:"预发布时间"`
  101. Stage int `description:"期数"`
  102. MsgIsSend int `description:"模板消息是否已发送,0:否,1:是"`
  103. Content string `description:"内容"`
  104. VideoUrl string `description:"音频文件URL"`
  105. VideoName string `description:"音频文件名称"`
  106. VideoPlaySeconds string `description:"音频播放时长"`
  107. ContentSub string `description:"内容前两个章节"`
  108. Pv int `description:"Pv"`
  109. Uv int `description:"Uv"`
  110. ReportCode string `description:"报告唯一编码"`
  111. ReportVersion int `description:"1:旧版,2:新版"`
  112. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  113. NeedThsMsg int `description:"是否需要推送客群消息 0-否 1-是"`
  114. HasChapter int `description:"是否有章节 0-否 1-是"`
  115. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  116. ChapterVideoList []*ReportChapterVideoList `description:"章节音频列表"`
  117. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  118. MsgSendTime string `description:"模版消息发送时间"`
  119. CanEdit bool `description:"是否可编辑"`
  120. Editor string `description:"编辑人"`
  121. AdminId int `description:"创建者账号"`
  122. AdminRealName string `description:"创建者姓名"`
  123. ApproveTime string `description:"审批时间"`
  124. DetailImgUrl string `description:"报告详情长图地址"`
  125. DetailPdfUrl string `description:"报告详情PDF地址"`
  126. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  127. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  128. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  129. ReportCreateTime time.Time `description:"报告时间创建时间"`
  130. ContentStruct string `description:"内容组件"`
  131. LastModifyAdminId int `description:"最后更新人ID"`
  132. LastModifyAdminName string `description:"最后更新人姓名"`
  133. ContentModifyTime time.Time `description:"内容更新时间"`
  134. HeadImg string `description:"报告头图地址"`
  135. EndImg string `description:"报告尾图地址"`
  136. CanvasColor string `description:"画布颜色"`
  137. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  138. HeadResourceId int `description:"版头资源ID"`
  139. EndResourceId int `description:"版尾资源ID"`
  140. ClassifyIdThird int `description:"三级分类id"`
  141. ClassifyNameThird string `description:"三级分类名称"`
  142. InheritReportId int `description:"待继承的报告ID"`
  143. }
  144. type ReportListResp struct {
  145. List []*ReportList
  146. Paging *paging.PagingItem `description:"分页数据"`
  147. }
  148. // GetReportListCountV1
  149. // @Description: 获取普通报告列表的报告数量
  150. // @author: Roc
  151. // @datetime 2024-05-30 15:14:43
  152. // @param condition string
  153. // @param pars []interface{}
  154. // @return count int
  155. // @return err error
  156. func GetReportListCountV1(condition string, pars []interface{}) (count int, err error) {
  157. o := orm.NewOrmUsingDB("rddp")
  158. sql := `SELECT COUNT(1) AS count FROM report as a WHERE 1=1 `
  159. if condition != "" {
  160. sql += condition
  161. }
  162. err = o.Raw(sql, pars).QueryRow(&count)
  163. return
  164. }
  165. // GetReportListV1
  166. // @Description: 获取普通报告列表的数据
  167. // @author: Roc
  168. // @datetime 2024-05-30 15:14:25
  169. // @param condition string
  170. // @param pars []interface{}
  171. // @param startSize int
  172. // @param pageSize int
  173. // @return items []*ReportList
  174. // @return err error
  175. func GetReportListV1(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  176. o := orm.NewOrmUsingDB("rddp")
  177. sql := `SELECT * FROM report as a WHERE 1=1 `
  178. if condition != "" {
  179. sql += condition
  180. }
  181. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  182. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  183. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  184. return
  185. }
  186. type ReportPvUv struct {
  187. ReportId int
  188. PvTotal int
  189. UvTotal int
  190. }
  191. func GetReportPvUvByReportIdList(reportIdList []string) (items []ReportPvUv, err error) {
  192. num := len(reportIdList)
  193. if num <= 0 {
  194. return
  195. }
  196. o := orm.NewOrmUsingDB("rddp")
  197. sql := `SELECT report_id, COUNT(1) as pv_total,COUNT(DISTINCT user_id) as uv_total FROM report_view_record WHERE report_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY report_id`
  198. _, err = o.Raw(sql, reportIdList).QueryRows(&items)
  199. return
  200. }
  201. // GetReportListCountByGrant
  202. // @Description: 获取共享报告列表的报告数量
  203. // @author: Roc
  204. // @datetime 2024-05-30 15:14:01
  205. // @param condition string
  206. // @param pars []interface{}
  207. // @return count int
  208. // @return err error
  209. func GetReportListCountByGrant(condition string, pars []interface{}) (count int, err error) {
  210. o := orm.NewOrmUsingDB("rddp")
  211. sql := `SELECT a.id FROM report as a
  212. JOIN report_grant b on a.id=b.report_id
  213. WHERE 1=1 `
  214. if condition != "" {
  215. sql += condition
  216. }
  217. sql += " GROUP BY a.id "
  218. sql = `SELECT COUNT(1) AS count FROM (` + sql + `) d`
  219. err = o.Raw(sql, pars).QueryRow(&count)
  220. return
  221. }
  222. // GetReportListByGrant
  223. // @Description: 获取共享报告列表的数据
  224. // @author: Roc
  225. // @datetime 2024-05-30 15:15:07
  226. // @param condition string
  227. // @param pars []interface{}
  228. // @param startSize int
  229. // @param pageSize int
  230. // @return items []*ReportList
  231. // @return err error
  232. func GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  233. o := orm.NewOrmUsingDB("rddp")
  234. sql := `SELECT * FROM report as a JOIN report_grant b on a.id = b.report_id WHERE 1=1 `
  235. if condition != "" {
  236. sql += condition
  237. }
  238. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  239. sql += ` GROUP BY a.id ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  240. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  241. return
  242. }
  243. func GetReportListCount(condition string, pars []interface{}) (count int, err error) {
  244. oRddp := orm.NewOrmUsingDB("rddp")
  245. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 `
  246. if condition != "" {
  247. sql += condition
  248. }
  249. err = oRddp.Raw(sql, pars).QueryRow(&count)
  250. return
  251. }
  252. func GetReportList(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  253. o := orm.NewOrmUsingDB("rddp")
  254. sql := `SELECT *,
  255. (SELECT COUNT(1) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS pv,
  256. (SELECT COUNT(DISTINCT user_id) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS uv
  257. FROM report WHERE 1=1 `
  258. if condition != "" {
  259. sql += condition
  260. }
  261. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  262. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  263. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  264. return
  265. }
  266. // PublishReport 发布报告
  267. func PublishReport(reportIds []int) (err error) {
  268. if len(reportIds) == 0 {
  269. return
  270. }
  271. o := orm.NewOrmUsingDB("rddp")
  272. sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  273. _, err = o.Raw(sql).Exec()
  274. return
  275. }
  276. // PublishCancelReport 取消发布报告
  277. func PublishCancelReport(reportId, state int, publishTimeNullFlag bool, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  278. o := orm.NewOrmUsingDB("rddp")
  279. var sql string
  280. if publishTimeNullFlag {
  281. sql = ` UPDATE report SET state=?, publish_time=null, pre_publish_time=null, pre_msg_send=0,last_modify_admin_id=?,last_modify_admin_name=?,modify_time = NOW() WHERE id =?`
  282. } else {
  283. sql = ` UPDATE report SET state=?, pre_publish_time=null, pre_msg_send=0,last_modify_admin_id=?,last_modify_admin_name=?,modify_time = NOW() WHERE id =?`
  284. }
  285. _, err = o.Raw(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Exec()
  286. return
  287. }
  288. // 删除报告
  289. func DeleteReport(reportIds int) (err error) {
  290. o := orm.NewOrmUsingDB("rddp")
  291. sql := ` DELETE FROM report WHERE id =? `
  292. _, err = o.Raw(sql, reportIds).Exec()
  293. return
  294. }
  295. type ReportDetail struct {
  296. Id int `orm:"column(id)" description:"报告Id"`
  297. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  298. ClassifyIdFirst int `description:"一级分类id"`
  299. ClassifyNameFirst string `description:"一级分类名称"`
  300. ClassifyIdSecond int `description:"二级分类id"`
  301. ClassifyNameSecond string `description:"二级分类名称"`
  302. Title string `description:"标题"`
  303. Abstract string `description:"摘要"`
  304. Author string `description:"作者"`
  305. Frequency string `description:"频度"`
  306. CreateTime string `description:"创建时间"`
  307. ModifyTime string `description:"修改时间"`
  308. State int `description:"1:未发布,2:已发布"`
  309. PublishTime string `description:"发布时间"`
  310. PrePublishTime string `description:"预发布时间"`
  311. Stage int `description:"期数"`
  312. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  313. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  314. Content string `description:"内容"`
  315. VideoUrl string `description:"音频文件URL"`
  316. VideoName string `description:"音频文件名称"`
  317. VideoPlaySeconds string `description:"音频播放时长"`
  318. ContentSub string `description:"内容前两个章节"`
  319. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  320. HasChapter int `description:"是否有章节 0-否 1-是"`
  321. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  322. AdminId int `description:"创建者账号"`
  323. AdminRealName string `description:"创建者姓名"`
  324. ReportCode string `description:"报告唯一编码"`
  325. // eta1.8.3(研报改版)相关内容
  326. ContentStruct string `description:"内容组件"`
  327. LastModifyAdminId int `description:"最后更新人ID"`
  328. LastModifyAdminName string `description:"最后更新人姓名"`
  329. ContentModifyTime time.Time `description:"内容更新时间"`
  330. Pv int `description:"pv"`
  331. Uv int `description:"uv"`
  332. HeadImg string `description:"报告头图地址"`
  333. EndImg string `description:"报告尾图地址"`
  334. HeadStyle string `description:"版头样式"`
  335. EndStyle string `description:"版尾样式"`
  336. CanvasColor string `description:"画布颜色"`
  337. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  338. HeadResourceId int `description:"版头资源ID"`
  339. EndResourceId int `description:"版尾资源ID"`
  340. ClassifyIdThird int `description:"三级分类id"`
  341. ClassifyNameThird string `description:"三级分类名称"`
  342. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  343. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  344. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  345. ReportCreateTime time.Time `description:"报告时间创建时间"`
  346. }
  347. func GetReportById(reportId int) (item *ReportDetail, err error) {
  348. o := orm.NewOrmUsingDB("rddp")
  349. sql := `SELECT * FROM report WHERE id=?`
  350. err = o.Raw(sql, reportId).QueryRow(&item)
  351. return
  352. }
  353. func GetReportByIds(reportIds string) (list []*ReportDetail, err error) {
  354. o := orm.NewOrmUsingDB("rddp")
  355. sql := `SELECT * FROM report WHERE id in ` + reportIds
  356. _, err = o.Raw(sql).QueryRows(&list)
  357. return
  358. }
  359. // GetSimpleReportByIds 根据报告ID查询报告基本信息
  360. func GetSimpleReportByIds(reportIds []int) (list []*Report, err error) {
  361. if len(reportIds) == 0 {
  362. return
  363. }
  364. o := orm.NewOrmUsingDB("rddp")
  365. sql := `SELECT id, title, report_code FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  366. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  367. return
  368. }
  369. // GetReportStage
  370. // @Description: 获取报告的最大期数(每一年的最大期数)
  371. // @author: Roc
  372. // @datetime 2024-06-03 17:44:14
  373. // @param classifyIdFirst int
  374. // @param classifyIdSecond int
  375. // @param classifyIdThird int
  376. // @return count int
  377. // @return err error
  378. func GetReportStage(classifyIdFirst, classifyIdSecond, classifyIdThird int) (count int, err error) {
  379. o := orm.NewOrmUsingDB("rddp")
  380. classifyId := classifyIdThird
  381. if classifyId <= 0 {
  382. classifyId = classifyIdSecond
  383. }
  384. if classifyId <= 0 {
  385. classifyId = classifyIdFirst
  386. }
  387. if classifyId <= 0 {
  388. err = errors.New("错误的分类id")
  389. return
  390. }
  391. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  392. sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? `
  393. if classifyIdThird > 0 {
  394. sql += " AND classify_id_third = ? "
  395. } else if classifyIdSecond > 0 {
  396. sql += " AND classify_id_second = ? "
  397. } else {
  398. sql += " AND classify_id_first = ? "
  399. }
  400. o.Raw(sql, yearStart, classifyId).QueryRow(&count)
  401. return
  402. }
  403. // GetReportStageEdit
  404. // @Description: 获取报告的最大期数(每一年的最大期数)
  405. // @author: Roc
  406. // @datetime 2024-06-04 13:50:34
  407. // @param classifyIdFirst int
  408. // @param classifyIdSecond int
  409. // @param classifyIdThird int
  410. // @param reportId int
  411. // @return count int
  412. // @return err error
  413. func GetReportStageEdit(classifyIdFirst, classifyIdSecond, classifyIdThird, reportId int) (count int, err error) {
  414. classifyId := classifyIdThird
  415. if classifyId <= 0 {
  416. classifyId = classifyIdSecond
  417. }
  418. if classifyId <= 0 {
  419. classifyId = classifyIdFirst
  420. }
  421. if classifyId <= 0 {
  422. err = errors.New("错误的分类id")
  423. return
  424. }
  425. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  426. sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? AND id<>? `
  427. if classifyIdThird > 0 {
  428. sql += " AND classify_id_third = ? "
  429. } else if classifyIdSecond > 0 {
  430. sql += " AND classify_id_second = ? "
  431. } else {
  432. sql = " AND classify_id_first = ? "
  433. }
  434. o := orm.NewOrmUsingDB("rddp")
  435. o.Raw(sql, yearStart, reportId, classifyId).QueryRow(&count)
  436. return
  437. }
  438. type PublishReq struct {
  439. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  440. ReportUrl string `description:"报告Url"`
  441. }
  442. type PublishCancelReq struct {
  443. ReportIds int `description:"报告id"`
  444. }
  445. type DeleteReq struct {
  446. ReportIds int `description:"报告id"`
  447. }
  448. type AddReq struct {
  449. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  450. ClassifyIdFirst int `description:"一级分类id"`
  451. ClassifyNameFirst string `description:"一级分类名称"`
  452. ClassifyIdSecond int `description:"二级分类id"`
  453. ClassifyNameSecond string `description:"二级分类名称"`
  454. ClassifyIdThird int `description:"三级分类id"`
  455. ClassifyNameThird string `description:"三级分类名称"`
  456. Title string `description:"标题"`
  457. Abstract string `description:"摘要"`
  458. Author string `description:"作者"`
  459. Frequency string `description:"频度"`
  460. State int `description:"状态:1:未发布,2:已发布"`
  461. Content string `description:"内容"`
  462. CreateTime string `description:"创建时间"`
  463. ReportVersion int `description:"1:旧版,2:新版"`
  464. ContentStruct string `description:"内容组件"`
  465. HeadImg string `description:"报告头图地址"`
  466. EndImg string `description:"报告尾图地址"`
  467. CanvasColor string `description:"画布颜色"`
  468. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  469. HeadResourceId int `description:"版头资源ID"`
  470. EndResourceId int `description:"版尾资源ID"`
  471. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  472. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  473. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  474. InheritReportId int `description:"待继承的报告ID"`
  475. GrantAdminIdList []int `description:"授权用户id列表"`
  476. }
  477. type PrePublishReq struct {
  478. ReportId int `description:"报告id"`
  479. PrePublishTime string `description:"预发布时间"`
  480. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  481. ReportUrl string `description:"报告Url"`
  482. }
  483. type AddResp struct {
  484. ReportId int64 `description:"报告id"`
  485. ReportCode string `description:"报告code"`
  486. }
  487. func AddReport(item *Report) (lastId int64, err error) {
  488. o := orm.NewOrmUsingDB("rddp")
  489. lastId, err = o.Insert(item)
  490. return
  491. }
  492. type EditReq struct {
  493. ReportId int64 `description:"报告id"`
  494. ClassifyIdFirst int `description:"一级分类id"`
  495. ClassifyNameFirst string `description:"一级分类名称"`
  496. ClassifyIdSecond int `description:"二级分类id"`
  497. ClassifyNameSecond string `description:"二级分类名称"`
  498. ClassifyIdThird int `description:"三级分类id"`
  499. ClassifyNameThird string `description:"三级分类名称"`
  500. Title string `description:"标题"`
  501. Abstract string `description:"摘要"`
  502. Author string `description:"作者"`
  503. Frequency string `description:"频度"`
  504. State int `description:"状态:1:未发布,2:已发布"`
  505. Content string `description:"内容"`
  506. CreateTime string `description:"创建时间"`
  507. ContentStruct string `description:"内容组件"`
  508. HeadImg string `description:"报告头图地址"`
  509. EndImg string `description:"报告尾图地址"`
  510. CanvasColor string `description:"画布颜色"`
  511. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  512. HeadResourceId int `description:"版头资源ID"`
  513. EndResourceId int `description:"版尾资源ID"`
  514. //CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  515. //ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  516. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  517. GrantAdminIdList []int `description:"授权用户id列表"`
  518. }
  519. type EditResp struct {
  520. ReportId int64 `description:"报告id"`
  521. ReportCode string `description:"报告code"`
  522. }
  523. func EditReport(item *Report, reportId int64) (err error) {
  524. o := orm.NewOrmUsingDB("rddp")
  525. sql := `UPDATE report
  526. SET
  527. classify_id_first =?,
  528. classify_name_first = ?,
  529. classify_id_second = ?,
  530. classify_name_second = ?,
  531. title = ?,
  532. abstract = ?,
  533. author = ?,
  534. frequency = ?,
  535. state = ?,
  536. content = ?,
  537. content_sub = ?,
  538. stage =?,
  539. create_time = ?,
  540. modify_time = ?
  541. WHERE id = ? `
  542. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  543. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec()
  544. return
  545. }
  546. func (m *Report) Update(cols []string) (err error) {
  547. o := orm.NewOrmUsingDB("rddp")
  548. _, err = o.Update(m, cols...)
  549. return
  550. }
  551. type ReportDetailReq struct {
  552. ReportId int `description:"报告id"`
  553. }
  554. type ClassifyIdDetailReq struct {
  555. ClassifyIdFirst int `description:"报告一级分类id"`
  556. ClassifyIdSecond int `description:"报告二级分类id"`
  557. }
  558. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  559. o := orm.NewOrmUsingDB("rddp")
  560. sql := ` SELECT * FROM report WHERE 1=1 `
  561. if classifyIdSecond > 0 {
  562. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  563. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  564. } else {
  565. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  566. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  567. }
  568. return
  569. }
  570. type SendTemplateMsgReq struct {
  571. ReportId int `description:"报告id"`
  572. }
  573. // SendTemplateMsgResp
  574. // @Description: 报告推送返回结构体
  575. type SendTemplateMsgResp struct {
  576. ReportId int `description:"报告id"`
  577. MsgSendTime string `description:"报告推送时间"`
  578. }
  579. func ModifyReportMsgIsSend(reportId int) (err error) {
  580. o := orm.NewOrmUsingDB("rddp")
  581. report, err := GetReportById(reportId)
  582. if err != nil {
  583. return
  584. }
  585. if report.MsgIsSend == 0 {
  586. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  587. _, err = o.Raw(sql, reportId).Exec()
  588. }
  589. return
  590. }
  591. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  592. o := orm.NewOrmUsingDB("rddp")
  593. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  594. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  595. return
  596. }
  597. type ReportItem struct {
  598. Id int `orm:"column(id)" description:"报告Id"`
  599. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  600. ClassifyIdFirst int `description:"一级分类id"`
  601. ClassifyNameFirst string `description:"一级分类名称"`
  602. ClassifyIdSecond int `description:"二级分类id"`
  603. ClassifyNameSecond string `description:"二级分类名称"`
  604. Title string `description:"标题"`
  605. Abstract string `description:"摘要"`
  606. Author string `description:"作者"`
  607. Frequency string `description:"频度"`
  608. CreateTime time.Time `description:"创建时间"`
  609. ModifyTime time.Time `description:"修改时间"`
  610. State int `description:"1:未发布,2:已发布"`
  611. PublishTime time.Time `description:"发布时间"`
  612. Stage int `description:"期数"`
  613. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  614. Content string `description:"内容"`
  615. VideoUrl string `description:"音频文件URL"`
  616. VideoName string `description:"音频文件名称"`
  617. VideoPlaySeconds string `description:"音频播放时长"`
  618. ContentSub string `description:"内容前两个章节"`
  619. }
  620. func GetReportItemById(reportId int) (item *ReportItem, err error) {
  621. o := orm.NewOrmUsingDB("rddp")
  622. sql := `SELECT * FROM report WHERE id=?`
  623. err = o.Raw(sql, reportId).QueryRow(&item)
  624. return
  625. }
  626. type SaveReportContent struct {
  627. Content string `description:"内容"`
  628. ReportId int `description:"报告id"`
  629. NoChange int `description:"内容是否未改变:1:内容未改变"`
  630. // 以下是智能研报相关
  631. ContentStruct string `description:"内容组件"`
  632. HeadImg string `description:"报告头图地址"`
  633. EndImg string `description:"报告尾图地址"`
  634. CanvasColor string `description:"画布颜色"`
  635. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  636. HeadResourceId int `description:"版头资源ID"`
  637. EndResourceId int `description:"版尾资源ID"`
  638. }
  639. func EditReportContent(reportId int, content, contentSub string) (err error) {
  640. o := orm.NewOrmUsingDB("rddp")
  641. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  642. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  643. return
  644. }
  645. func AddReportSaveLog(reportId, adminId int, content, contentSub, contentStruct, canvasColor, adminName string, headResourceId, endResourceId int) (err error) {
  646. o := orm.NewOrmUsingDB("rddp")
  647. sql := ` INSERT INTO report_save_log(report_id, content,content_sub,content_struct,canvas_color,head_resource_id,end_resource_id,admin_id,admin_name) VALUES (?,?,?,?,?) `
  648. _, err = o.Raw(sql, reportId, content, contentSub, contentStruct, canvasColor, headResourceId, endResourceId, adminId, adminName).Exec()
  649. return
  650. }
  651. func MultiAddReportChaptersSaveLog(items []*ReportChapter, adminId int, adminRealName string) (err error) {
  652. o := orm.NewOrmUsingDB("rddp")
  653. p, err := o.Raw(`INSERT INTO report_save_log(report_id, report_chapter_id, content, content_sub,content_struct,admin_id, admin_name) VALUES (?,?,?,?,?,?,?)`).Prepare()
  654. if err != nil {
  655. return
  656. }
  657. defer func() {
  658. _ = p.Close()
  659. }()
  660. for _, v := range items {
  661. _, err = p.Exec(v.ReportId, v.ReportChapterId, v.Content, v.ContentSub, v.ContentStruct, adminId, adminRealName)
  662. if err != nil {
  663. return
  664. }
  665. }
  666. return
  667. }
  668. type SaveReportContentResp struct {
  669. ReportId int `description:"报告id"`
  670. }
  671. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  672. o := orm.NewOrmUsingDB("rddp")
  673. sql := `UPDATE report SET report_code=? WHERE id=? `
  674. _, err = o.Raw(sql, reportCode, reportId).Exec()
  675. return
  676. }
  677. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  678. o := orm.NewOrmUsingDB("rddp")
  679. if item.ThsMsgIsSend == 0 {
  680. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  681. _, err = o.Raw(sql, item.Id).Exec()
  682. }
  683. return
  684. }
  685. type ThsSendTemplateMsgReq struct {
  686. ReportId []int `description:"报告id"`
  687. }
  688. type PublishDayWeekReportReq struct {
  689. ReportId int `description:"报告ID"`
  690. }
  691. // SaveDayWeekReportReq 新增晨报周报请求体
  692. type SaveDayWeekReportReq struct {
  693. ReportId int `description:"报告ID"`
  694. Title string `description:"标题"`
  695. ReportType string `description:"一级分类ID"`
  696. Author string `description:"作者"`
  697. CreateTime string `description:"创建时间"`
  698. }
  699. // GetDayWeekReportStage 获取晨报周报期数
  700. func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  701. o := orm.NewOrmUsingDB("rddp")
  702. sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  703. o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  704. return
  705. }
  706. // GetReportByReportId 主键获取报告
  707. func GetReportByReportId(reportId int) (item *Report, err error) {
  708. o := orm.NewOrmUsingDB("rddp")
  709. sql := `SELECT * FROM report WHERE id = ?`
  710. err = o.Raw(sql, reportId).QueryRow(&item)
  711. return
  712. }
  713. // GetReportByOldReportId 根据老报告id主键获取报告
  714. func GetReportByOldReportId(reportId int) (item *Report, err error) {
  715. o := orm.NewOrmUsingDB("rddp")
  716. sql := `SELECT * FROM report WHERE old_report_id = ?`
  717. err = o.Raw(sql, reportId).QueryRow(&item)
  718. return
  719. }
  720. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  721. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  722. o := orm.NewOrmUsingDB("rddp")
  723. to, err := o.Begin()
  724. if err != nil {
  725. return
  726. }
  727. defer func() {
  728. if err != nil {
  729. _ = to.Rollback()
  730. } else {
  731. _ = to.Commit()
  732. }
  733. }()
  734. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  735. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  736. return
  737. }
  738. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  739. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  740. return
  741. }
  742. return
  743. }
  744. // UpdateReport 更新报告
  745. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  746. o := orm.NewOrmUsingDB("rddp")
  747. _, err = o.Update(reportInfo, cols...)
  748. return
  749. }
  750. // ReportDetailView
  751. // @Description: 晨周报详情
  752. type ReportDetailView struct {
  753. *ReportDetail
  754. ChapterList []*ReportChapter
  755. GrandAdminList []ReportDetailViewAdmin
  756. PermissionList []ReportDetailViewPermission
  757. }
  758. // ReportDetailViewAdmin
  759. // @Description: 报告里面的授权人
  760. type ReportDetailViewAdmin struct {
  761. AdminId int
  762. AdminName string
  763. }
  764. // ReportDetailViewPermission
  765. // @Description: 报告分类关联的品种权限
  766. type ReportDetailViewPermission struct {
  767. PermissionId int
  768. PermissionName string
  769. }
  770. func GetUnPublishDayReport(startTime time.Time, endTime time.Time) (item *Report, err error) {
  771. o := orm.NewOrmUsingDB("rddp")
  772. sql := ` SELECT
  773. *
  774. FROM
  775. report AS a
  776. WHERE
  777. a.has_chapter = 1
  778. AND a.chapter_type = "day"
  779. AND a.state = 1
  780. AND (
  781. a.create_time BETWEEN ? AND ?
  782. )
  783. ORDER BY
  784. a.create_time DESC
  785. LIMIT 1 `
  786. err = o.Raw(sql, startTime, endTime).QueryRow(&item)
  787. return
  788. }
  789. type ElasticReportDetail struct {
  790. ReportId int `description:"报告ID"`
  791. ReportChapterId int `description:"报告章节ID"`
  792. Title string `description:"标题"`
  793. Abstract string `description:"摘要"`
  794. BodyContent string `description:"内容"`
  795. PublishTime string `description:"发布时间"`
  796. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  797. Author string `description:"作者"`
  798. ClassifyIdFirst int `description:"一级分类ID"`
  799. ClassifyNameFirst string `description:"一级分类名称"`
  800. ClassifyIdSecond int `description:"二级分类ID"`
  801. ClassifyNameSecond string `description:"二级分类名称"`
  802. ClassifyId int `description:"最小单元的分类ID"`
  803. ClassifyName string `description:"最小单元的分类名称"`
  804. Categories string `description:"关联的品种名称(包括品种别名)"`
  805. StageStr string `description:"报告期数"`
  806. }
  807. // GetLastPublishedDayWeekReport 获取上一篇已发布的晨周报
  808. func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  809. o := orm.NewOrmUsingDB("rddp")
  810. sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  811. err = o.Raw(sql, chapterType).QueryRow(&item)
  812. return
  813. }
  814. // GetNewReportExist
  815. func GetNewReportExist(oldReportId int) (item *Report, err error) {
  816. o := orm.NewOrmUsingDB("rddp")
  817. sql := ` SELECT id FROM report WHERE old_report_id = ? LIMIT 1 `
  818. err = o.Raw(sql, oldReportId).QueryRow(&item)
  819. return
  820. }
  821. // PublishReportAndChapter 发布报告及章节
  822. func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []string) (err error) {
  823. o := orm.NewOrmUsingDB("rddp")
  824. to, err := o.Begin()
  825. if err != nil {
  826. return
  827. }
  828. defer func() {
  829. if err != nil {
  830. _ = to.Rollback()
  831. } else {
  832. _ = to.Commit()
  833. }
  834. }()
  835. // 更新报告
  836. if isPublishReport {
  837. _, err = to.Update(reportInfo, cols...)
  838. if err != nil {
  839. return
  840. }
  841. }
  842. // 发布该报告的所有章节
  843. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
  844. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id).Exec()
  845. // 发布章节
  846. //if len(publishIds) > 0 {
  847. // sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  848. // _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  849. //}
  850. //if len(unPublishIds) > 0 {
  851. // 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)) + `) `
  852. // _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  853. //}
  854. return
  855. }
  856. func GetSyncEmptyVideoReport() (list []*Report, err error) {
  857. o := orm.NewOrmUsingDB("rddp")
  858. sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  859. UNION ALL
  860. SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  861. _, err = o.Raw(sql).QueryRows(&list)
  862. return
  863. }
  864. // PublishReportById 发布报告
  865. func PublishReportById(reportId int, publishTime time.Time, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  866. o := orm.NewOrmUsingDB("rddp")
  867. sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW(),last_modify_admin_id=?,last_modify_admin_name=? WHERE id = ? `
  868. _, err = o.Raw(sql, publishTime, lastModifyAdminId, lastModifyAdminName, reportId).Exec()
  869. return
  870. }
  871. // ResetReportById 重置报告状态
  872. func ResetReportById(reportId, state int, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  873. o := orm.NewOrmUsingDB("rddp")
  874. sql := `UPDATE report SET state = ?, pre_publish_time = null, pre_msg_send = 0, modify_time = NOW(),last_modify_admin_id=?,last_modify_admin_name=? WHERE id = ?`
  875. _, err = o.Raw(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Exec()
  876. return
  877. }
  878. // GetCommentReportByReportId 查询有留言的报告列表
  879. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  880. o := orm.NewOrmUsingDB("rddp")
  881. sql := `SELECT
  882. id,
  883. create_time,
  884. title,
  885. classify_name_first,
  886. classify_id_first,
  887. classify_name_second,
  888. classify_id_second,
  889. state,
  890. IF
  891. ( publish_time, publish_time, create_time ) AS publish_time
  892. FROM
  893. report
  894. WHERE
  895. 1=1
  896. `
  897. if condition != "" {
  898. sql += condition
  899. }
  900. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  901. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  902. return
  903. }
  904. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  905. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  906. o := orm.NewOrmUsingDB("rddp")
  907. sql := `SELECT
  908. id,
  909. create_time,
  910. title,
  911. classify_name_first,
  912. classify_id_first,
  913. classify_name_second,
  914. classify_id_second,
  915. state,
  916. IF
  917. ( publish_time, publish_time, create_time ) AS publish_time
  918. FROM
  919. report
  920. WHERE
  921. 1=1
  922. `
  923. if condition != "" {
  924. sql += condition
  925. }
  926. if orderBy == `` {
  927. sql += ` ORDER BY publish_time DESC , title ASC `
  928. } else {
  929. sql += orderBy
  930. }
  931. sql += ` LIMIT ?,? `
  932. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  933. return
  934. }
  935. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  936. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  937. o := orm.NewOrmUsingDB("rddp")
  938. sql := `SELECT count(*)
  939. FROM report WHERE 1=1`
  940. if condition != "" {
  941. sql += condition
  942. }
  943. err = o.Raw(sql, pars).QueryRow(&total)
  944. return
  945. }
  946. // 点赞相关的报告列表
  947. type LikeReportItem struct {
  948. ReportId int `description:"报告Id"`
  949. ReportChapterId int `description:"报告章节Id"`
  950. ClassifyIdFirst int `description:"一级分类id"`
  951. ClassifyNameFirst string `description:"一级分类名称"`
  952. ClassifyIdSecond int `description:"二级分类id"`
  953. ClassifyNameSecond string `description:"二级分类名称"`
  954. ReportChapterTypeId int `description:"章节类型"`
  955. ReportChapterTypeName string `description:"品种名称"`
  956. PublishTime time.Time `description:"发布时间" `
  957. Title string `description:"标题"`
  958. }
  959. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  960. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  961. o := orm.NewOrmUsingDB("rddp")
  962. sql := `( SELECT
  963. id AS report_id,
  964. 0 AS report_chapter_id,
  965. classify_id_first,
  966. classify_id_second,
  967. classify_name_first,
  968. classify_name_second,
  969. 0 as report_chapter_type_id,
  970. "" as report_chapter_type_name,
  971. publish_time,
  972. title
  973. FROM
  974. report
  975. WHERE
  976. classify_name_first != "晨报"
  977. AND classify_name_first != "周报"
  978. AND id in (` + reportIds + `)
  979. )
  980. UNION
  981. ( SELECT
  982. report_id,
  983. report_chapter_id,
  984. classify_id_first,
  985. 0 as classify_id_second,
  986. classify_name_first,
  987. null as classify_name_second,
  988. type_id as report_chapter_type_id,
  989. type_name as report_chapter_type_name,
  990. publish_time,
  991. title
  992. FROM
  993. report_chapter
  994. WHERE
  995. report_chapter_id in (` + chapterIds + `)
  996. )`
  997. if orderStr != "" {
  998. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  999. } else {
  1000. sql += ` ORDER BY publish_time DESC, report_id Desc`
  1001. }
  1002. sql += ` LIMIT ?,?`
  1003. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  1004. return
  1005. }
  1006. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  1007. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  1008. o := orm.NewOrmUsingDB("rddp")
  1009. sql := `select count(*) from (( SELECT
  1010. id AS report_id,
  1011. 0 AS report_chapter_id,
  1012. classify_id_first,
  1013. classify_id_second,
  1014. classify_name_first,
  1015. classify_name_second,
  1016. 0 as report_chapter_type_id,
  1017. publish_time,
  1018. title
  1019. FROM
  1020. report
  1021. WHERE
  1022. classify_name_first != "晨报"
  1023. AND classify_name_first != "周报"
  1024. AND id in (` + reportIds + `)
  1025. )
  1026. UNION
  1027. ( SELECT
  1028. report_id,
  1029. report_chapter_id,
  1030. classify_id_first,
  1031. 0 as classify_id_second,
  1032. classify_name_first,
  1033. null as classify_name_second,
  1034. type_id as report_chapter_type_id,
  1035. publish_time,
  1036. title
  1037. FROM
  1038. report_chapter
  1039. WHERE
  1040. report_chapter_id in (` + chapterIds + `)
  1041. )) r`
  1042. err = o.Raw(sql).QueryRow(&total)
  1043. return
  1044. }
  1045. // GetPageReportList 分页获取报告列表
  1046. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  1047. o := orm.NewOrmUsingDB("rddp")
  1048. sql := `SELECT * FROM report WHERE 1=1 `
  1049. sql += condition
  1050. sql += ` ORDER BY modify_time DESC`
  1051. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1052. err = o.Raw(totalSql, pars).QueryRow(&total)
  1053. if err != nil {
  1054. return
  1055. }
  1056. sql += ` LIMIT ?,? `
  1057. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1058. return
  1059. }
  1060. // SunCodeReq 获取太阳码请求体
  1061. type SunCodeReq struct {
  1062. CodePage string `json:"CodePage" description:"太阳码page"`
  1063. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  1064. }
  1065. // YbPcSuncode 活动海报表
  1066. type YbPcSuncode struct {
  1067. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  1068. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  1069. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  1070. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  1071. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  1072. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  1073. }
  1074. // GetYbPcSunCode 获取太阳码
  1075. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  1076. o := orm.NewOrmUsingDB("weekly")
  1077. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  1078. err = o.Raw(sql, scene, page).QueryRow(&item)
  1079. return
  1080. }
  1081. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  1082. o := orm.NewOrmUsingDB("weekly")
  1083. _, err = o.Insert(item)
  1084. return
  1085. }
  1086. // YbSuncodePars 小程序太阳码scene参数
  1087. type YbSuncodePars struct {
  1088. ID uint32 `orm:"column(id);pk" `
  1089. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  1090. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  1091. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  1092. }
  1093. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  1094. o := orm.NewOrmUsingDB("weekly")
  1095. _, err = o.Insert(item)
  1096. return
  1097. }
  1098. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  1099. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1100. o := orm.NewOrmUsingDB("rddp")
  1101. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  1102. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1103. return
  1104. }
  1105. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  1106. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1107. o := orm.NewOrmUsingDB("rddp")
  1108. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  1109. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1110. return
  1111. }
  1112. // UpdateReportThirdClassifyNameByClassifyId 更新报告的三级分类名称字段
  1113. func UpdateReportThirdClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1114. o := orm.NewOrmUsingDB("rddp")
  1115. sql := " UPDATE report SET classify_name_third = ? WHERE classify_id_third = ? "
  1116. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1117. return
  1118. }
  1119. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  1120. func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  1121. o := orm.NewOrmUsingDB("rddp")
  1122. sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  1123. _, err = o.Raw(sql, classifyName, newClassifyId, classifyId).Exec()
  1124. return
  1125. }
  1126. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  1127. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  1128. sql := `SELECT
  1129. r.id,
  1130. r.content,
  1131. r.content_sub
  1132. FROM
  1133. report AS r
  1134. JOIN ppt_v2 AS p ON r.id = p.report_id
  1135. WHERE
  1136. p.report_id > 0 AND r.content_sub = ""`
  1137. _, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  1138. return
  1139. }
  1140. // ModifyReportAuthor 更改报告作者
  1141. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  1142. //产品权限
  1143. oRddp := orm.NewOrmUsingDB("rddp")
  1144. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  1145. if condition != "" {
  1146. sql += condition
  1147. }
  1148. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  1149. return
  1150. }
  1151. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  1152. o := orm.NewOrmUsingDB("rddp")
  1153. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  1154. _, err = o.Raw(sql1, reportId).Exec()
  1155. if err != nil {
  1156. return
  1157. }
  1158. //修改音频标题
  1159. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  1160. _, err = o.Raw(sql2, reportId).Exec()
  1161. return
  1162. }
  1163. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  1164. o := orm.NewOrmUsingDB("rddp")
  1165. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  1166. _, err = o.Raw(sql1, reportId).Exec()
  1167. if err != nil {
  1168. return
  1169. }
  1170. //修改音频标题
  1171. 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)`
  1172. _, err = o.Raw(sql2, reportId).Exec()
  1173. return
  1174. }
  1175. // MarkEditReport 标记编辑英文研报的请求数据
  1176. type MarkEditReport struct {
  1177. ReportId int `description:"研报id"`
  1178. ReportChapterId int `description:"研报章节id"`
  1179. Status int `description:"标记状态,1:编辑中,2:查询状态,3:编辑完成"`
  1180. }
  1181. type MarkReportResp struct {
  1182. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  1183. Msg string `description:"提示信息"`
  1184. Editor string `description:"编辑者姓名"`
  1185. }
  1186. type MarkReportItem struct {
  1187. AdminId int `description:"编辑者ID"`
  1188. Editor string `description:"编辑者姓名"`
  1189. ReportClassifyNameFirst string
  1190. }
  1191. // GetReportByCondition 获取报告
  1192. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  1193. o := orm.NewOrmUsingDB("rddp")
  1194. fields := `*`
  1195. if len(fieldArr) > 0 {
  1196. fields = strings.Join(fieldArr, ",")
  1197. }
  1198. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  1199. sql += condition
  1200. order := ` ORDER BY modify_time DESC`
  1201. if orderRule != `` {
  1202. order = orderRule
  1203. }
  1204. sql += order
  1205. if isPage {
  1206. sql += ` LIMIT ?,?`
  1207. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1208. } else {
  1209. _, err = o.Raw(sql, pars).QueryRows(&items)
  1210. }
  1211. return
  1212. }
  1213. // ModifyReportMsgIsSendV2 更新报告消息状态
  1214. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  1215. o := orm.NewOrmUsingDB("rddp")
  1216. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  1217. _, err = o.Raw(sql, reportId).Exec()
  1218. return
  1219. }
  1220. // SetPrePublishReportById 设置定时发布
  1221. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  1222. o := orm.NewOrmUsingDB("rddp")
  1223. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  1224. _, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  1225. return
  1226. }
  1227. // ReportSubmitApproveReq 提交审批请求体
  1228. type ReportSubmitApproveReq struct {
  1229. ReportId int `description:"报告ID"`
  1230. }
  1231. // ReportCancelApproveReq 撤回审批请求体
  1232. type ReportCancelApproveReq struct {
  1233. ReportId int `description:"报告ID"`
  1234. }
  1235. func (m *Report) GetItemById(id int) (item *Report, err error) {
  1236. o := orm.NewOrmUsingDB("rddp")
  1237. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  1238. err = o.Raw(sql, id).QueryRow(&item)
  1239. return
  1240. }
  1241. // GetReportStateCount 获取指定状态的报告数量
  1242. func GetReportStateCount(state int) (count int, err error) {
  1243. o := orm.NewOrmUsingDB("rddp")
  1244. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  1245. err = o.Raw(sql, state).QueryRow(&count)
  1246. return
  1247. }
  1248. // UpdateReportsStateByCond 批量更新报告状态
  1249. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, classifyThirdId, oldState, newState int) (err error) {
  1250. o := orm.NewOrmUsingDB("rddp")
  1251. cond := ``
  1252. if classifyFirstId > 0 {
  1253. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  1254. }
  1255. if classifySecondId > 0 {
  1256. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  1257. }
  1258. if classifyThirdId > 0 {
  1259. cond += fmt.Sprintf(` AND classify_id_third = %d`, classifyThirdId)
  1260. }
  1261. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  1262. _, err = o.Raw(sql, newState, oldState).Exec()
  1263. return
  1264. }
  1265. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  1266. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  1267. if len(secondIds) <= 0 {
  1268. return
  1269. }
  1270. o := orm.NewOrmUsingDB("rddp")
  1271. // (有审批流的)未发布->待提交
  1272. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1273. _, err = o.Raw(sql, newState, oldState, secondIds).Exec()
  1274. if err != nil {
  1275. return
  1276. }
  1277. // (无审批流的)待提交->未发布
  1278. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1279. _, err = o.Raw(sql, oldState, newState, secondIds).Exec()
  1280. return
  1281. }
  1282. // GetReportPdfUrlReq 获取报告pdf地址请求体
  1283. type GetReportPdfUrlReq struct {
  1284. ReportUrl string `description:"报告Url"`
  1285. ReportCode string `description:"报告Code"`
  1286. Type int `description:"类型 1-pdf 2-图片"`
  1287. }
  1288. func ModifyReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  1289. o := orm.NewOrmUsingDB("rddp")
  1290. sql := `UPDATE report SET detail_pdf_url=? WHERE id=? `
  1291. _, err = o.Raw(sql, detailPdfUrl, reportId).Exec()
  1292. return
  1293. }
  1294. func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
  1295. o := orm.NewOrmUsingDB("rddp")
  1296. sql := `UPDATE report SET detail_img_url=? WHERE id=? `
  1297. _, err = o.Raw(sql, detailImgUrl, reportId).Exec()
  1298. return
  1299. }
  1300. // UpdatePdfUrlReportById 清空pdf相关字段
  1301. func UpdatePdfUrlReportById(reportId int) (err error) {
  1302. o := orm.NewOrmUsingDB("rddp")
  1303. sql := `UPDATE report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE id = ? `
  1304. _, err = o.Raw(sql, reportId).Exec()
  1305. return
  1306. }
  1307. // InsertMultiReport
  1308. // @Description: 批量新增报告
  1309. // @author: Roc
  1310. // @datetime 2024-06-27 15:55:25
  1311. // @param items []*Report
  1312. // @return err error
  1313. func InsertMultiReport(items []*Report) (err error) {
  1314. o := orm.NewOrmUsingDB("rddp")
  1315. _, err = o.InsertMulti(500, items)
  1316. return
  1317. }
  1318. // ReportLayout
  1319. // @Description: 报告布局
  1320. type ReportLayout struct {
  1321. Id int
  1322. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  1323. }
  1324. // GetReportLayoutByReportId
  1325. // @Description: 根据报告id获取报告的布局
  1326. // @author: Roc
  1327. // @datetime 2024-07-15 15:27:05
  1328. // @param reportId int
  1329. // @return item ReportLayout
  1330. // @return err error
  1331. func GetReportLayoutByReportId(reportId int) (item ReportLayout, err error) {
  1332. o := orm.NewOrmUsingDB("rddp")
  1333. sql := `SELECT id, report_layout FROM report WHERE id = ? `
  1334. err = o.Raw(sql, reportId).QueryRow(&item)
  1335. return
  1336. }