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