report.go 66 KB

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