report.go 55 KB

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