report.go 59 KB

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