report.go 58 KB

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