report.go 66 KB

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