report.go 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. package models
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta_gn/eta_api/global"
  6. "eta_gn/eta_api/utils"
  7. "fmt"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. "gorm.io/gorm"
  10. "strings"
  11. "time"
  12. )
  13. // 报告状态
  14. const (
  15. ReportStateUnpublished = 1 // 未发布
  16. ReportStatePublished = 2 // 已发布
  17. ReportStateWaitSubmit = 3 // 待提交
  18. ReportStateWaitApprove = 4 // 审批中
  19. ReportStateRefused = 5 // 已驳回
  20. ReportStatePass = 6 // 已通过
  21. )
  22. // 报告操作
  23. const (
  24. ReportOperateAdd = 1 // 新增报告
  25. ReportOperateEdit = 2 // 编辑报告
  26. ReportOperatePublish = 3 // 发布报告
  27. ReportOperateCancelPublish = 4 // 取消发布报告
  28. ReportOperateSubmitApprove = 5 // 提交审批
  29. ReportOperateCancelApprove = 6 // 撤回审批
  30. )
  31. type Report struct {
  32. Id int `gorm:"column:id;primaryKey;autoIncrement" description:"报告Id"`
  33. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  34. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  35. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  36. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  37. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  38. Title string `gorm:"column:title" description:"标题"`
  39. Abstract string `gorm:"column:abstract" description:"摘要"`
  40. Author string `gorm:"column:author" description:"作者"`
  41. Frequency string `gorm:"column:frequency" description:"频度"`
  42. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  43. ModifyTime time.Time `gorm:"column:modify_time;autoUpdateTime" description:"修改时间"`
  44. State int `gorm:"column:state" description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  45. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  46. Stage int `gorm:"column:stage" description:"期数"`
  47. MsgIsSend int `gorm:"column:msg_is_send" description:"消息是否已发送,0:否,1:是"`
  48. ThsMsgIsSend int `gorm:"column:ths_msg_is_send" description:"客户群消息是否已发送,0:否,1:是"`
  49. Content string `gorm:"column:content" description:"内容"`
  50. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  51. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  52. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  53. VideoSize string `gorm:"column:video_size" description:"音频文件大小,单位M"`
  54. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  55. ReportCode string `gorm:"column:report_code" description:"报告唯一编码"`
  56. ReportVersion int `gorm:"column:report_version" description:"1:旧版,2:新版"`
  57. HasChapter int `gorm:"column:has_chapter" description:"是否有章节 0-否 1-是"`
  58. ChapterType string `gorm:"column:chapter_type" description:"章节类型 day-晨报 week-周报"`
  59. OldReportId int `gorm:"column:old_report_id" description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  60. MsgSendTime time.Time `gorm:"column:msg_send_time" description:"模版消息发送时间"`
  61. AdminId int `gorm:"column:admin_id" description:"创建者账号"`
  62. AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
  63. ApproveTime time.Time `gorm:"column:approve_time" description:"审批时间"`
  64. ApproveId int `gorm:"column:approve_id" description:"审批ID"`
  65. DetailImgUrl string `gorm:"column:detail_img_url" description:"报告详情长图地址"`
  66. DetailPdfUrl string `gorm:"column:detail_pdf_url" description:"报告详情PDF地址"`
  67. ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
  68. LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
  69. LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
  70. ContentModifyTime time.Time `gorm:"column:content_modify_time" description:"内容更新时间"`
  71. Pv int `gorm:"column:pv" description:"pv"`
  72. Uv int `gorm:"column:uv" description:"uv"`
  73. HeadImg string `gorm:"column:head_img" description:"报告头图地址"`
  74. EndImg string `gorm:"column:end_img" description:"报告尾图地址"`
  75. CanvasColor string `gorm:"column:canvas_color" description:"画布颜色"`
  76. NeedSplice int `gorm:"column:need_splice" description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  77. HeadResourceId int `gorm:"column:head_resource_id" description:"版头资源ID"`
  78. EndResourceId int `gorm:"column:end_resource_id" description:"版尾资源ID"`
  79. ClassifyIdThird int `gorm:"column:classify_id_third" description:"三级分类id"`
  80. ClassifyNameThird string `gorm:"column:classify_name_third" description:"三级分类名称"`
  81. CollaborateType int8 `gorm:"column:collaborate_type" description:"协作方式,1:个人,2:多人协作。默认:1"`
  82. ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  83. IsPublicPublish int8 `gorm:"column:is_public_publish" description:"是否公开发布,1:是,2:否"`
  84. ReportCreateTime time.Time `gorm:"column:report_create_time" description:"报告时间创建时间"`
  85. InheritReportId int `gorm:"column:inherit_report_id" description:"待继承的报告ID"`
  86. VoiceGenerateType int `gorm:"column:voice_generate_type" description:"音频生成方式,0:系统生成,1:人工上传"`
  87. }
  88. type ReportList struct {
  89. Id int `gorm:"column:id" description:"报告Id"`
  90. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  91. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  92. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  93. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  94. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  95. Title string `gorm:"column:title" description:"标题"`
  96. Abstract string `gorm:"column:abstract" description:"摘要"`
  97. Author string `gorm:"column:author" description:"作者"`
  98. Frequency string `gorm:"column:frequency" description:"频度"`
  99. CreateTime *global.LocalTime `gorm:"column:create_time" description:"创建时间"`
  100. ModifyTime *global.LocalTime `gorm:"column:modify_time;autoUpdateTime" description:"修改时间"`
  101. State int `gorm:"column:state" description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  102. PublishTime *global.LocalTime `gorm:"column:publish_time" description:"发布时间"`
  103. PrePublishTime string `gorm:"column:pre_publish_time" description:"预发布时间"`
  104. Stage int `gorm:"column:stage" description:"期数"`
  105. MsgIsSend int `gorm:"column:msg_is_send" description:"模板消息是否已发送,0:否,1:是"`
  106. Content string `gorm:"column:content" description:"内容"`
  107. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  108. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  109. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  110. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  111. Pv int `gorm:"column:pv" description:"Pv"`
  112. Uv int `gorm:"column:uv" description:"Uv"`
  113. ReportCode string `gorm:"column:report_code" description:"报告唯一编码"`
  114. ReportVersion int `gorm:"column:report_version" description:"1:旧版,2:新版"`
  115. ThsMsgIsSend int `gorm:"column:ths_msg_is_send" description:"客户群消息是否已发送,0:否,1:是"`
  116. NeedThsMsg int `gorm:"column:need_ths_msg" description:"是否需要推送客群消息 0-否 1-是"`
  117. HasChapter int `gorm:"column:has_chapter" description:"是否有章节 0-否 1-是"`
  118. ChapterType string `gorm:"column:chapter_type" description:"章节类型 day-晨报 week-周报"`
  119. ChapterVideoList []*ReportChapterVideoList `gorm:"-" description:"章节音频列表"` // 不映射到数据库
  120. OldReportId int `gorm:"column:old_report_id" description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  121. MsgSendTime *global.LocalTime `gorm:"column:msg_send_time" description:"模版消息发送时间"`
  122. CanEdit bool `gorm:"column:can_edit" description:"是否可编辑"`
  123. HasAuth bool `gorm:"column:has_auth" description:"是否可操作"`
  124. Editor string `gorm:"column:editor" description:"编辑人"`
  125. AdminId int `gorm:"column:admin_id" description:"创建者账号"`
  126. AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
  127. ApproveTime *global.LocalTime `gorm:"column:approve_time" description:"审批时间"`
  128. DetailImgUrl string `gorm:"column:detail_img_url" description:"报告详情长图地址"`
  129. DetailPdfUrl string `gorm:"column:detail_pdf_url" description:"报告详情PDF地址"`
  130. CollaborateType int8 `gorm:"column:collaborate_type" description:"协作方式,1:个人,2:多人协作。默认:1"`
  131. ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  132. IsPublicPublish int8 `gorm:"column:is_public_publish" description:"是否公开发布,1:是,2:否"`
  133. ReportCreateTime *global.LocalTime `gorm:"column:report_create_time" description:"报告时间创建时间"`
  134. ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
  135. LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
  136. LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
  137. ContentModifyTime *global.LocalTime `gorm:"column:content_modify_time" description:"内容更新时间"`
  138. HeadImg string `gorm:"column:head_img" description:"报告头图地址"`
  139. EndImg string `gorm:"column:end_img" description:"报告尾图地址"`
  140. CanvasColor string `gorm:"column:canvas_color" description:"画布颜色"`
  141. NeedSplice int `gorm:"column:need_splice" description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  142. HeadResourceId int `gorm:"column:head_resource_id" description:"版头资源ID"`
  143. EndResourceId int `gorm:"column:end_resource_id" description:"版尾资源ID"`
  144. ClassifyIdThird int `gorm:"column:classify_id_third" description:"三级分类id"`
  145. ClassifyNameThird string `gorm:"column:classify_name_third" description:"三级分类名称"`
  146. InheritReportId int `gorm:"column:inherit_report_id" description:"待继承的报告ID"`
  147. }
  148. type ReportListResp struct {
  149. List []*ReportList
  150. Paging *paging.PagingItem `description:"分页数据"`
  151. }
  152. // GetReportListCountV1
  153. // @Description: 获取普通报告列表的报告数量
  154. // @author: Roc
  155. // @datetime 2024-05-30 15:14:43
  156. // @param condition string
  157. // @param pars []interface{}
  158. // @return count int
  159. // @return err error
  160. func GetReportListCountV1(condition string, pars []interface{}) (count int, err error) {
  161. sql := `SELECT COUNT(1) AS count FROM report as a WHERE 1=1 `
  162. if condition != "" {
  163. sql += condition
  164. }
  165. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  166. return
  167. }
  168. // GetReportListV1
  169. // @Description: 获取普通报告列表的数据
  170. // @author: Roc
  171. // @datetime 2024-05-30 15:14:25
  172. // @param condition string
  173. // @param pars []interface{}
  174. // @param startSize int
  175. // @param pageSize int
  176. // @return items []*ReportList
  177. // @return err error
  178. func GetReportListV1(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  179. sql := `SELECT * FROM report as a WHERE 1=1 `
  180. if condition != "" {
  181. sql += condition
  182. }
  183. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  184. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  185. pars = append(pars, startSize)
  186. pars = append(pars, pageSize)
  187. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  188. return
  189. }
  190. type ReportPvUv struct {
  191. ReportId int
  192. PvTotal int
  193. UvTotal int
  194. }
  195. func GetReportPvUvByReportIdList(reportIdList []int) (items []ReportPvUv, err error) {
  196. num := len(reportIdList)
  197. if num <= 0 {
  198. return
  199. }
  200. 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`
  201. err = global.DmSQL["rddp"].Raw(sql, reportIdList).Find(&items).Error
  202. return
  203. }
  204. // GetReportListCountByGrant
  205. // @Description: 获取共享报告列表的报告数量
  206. // @author: Roc
  207. // @datetime 2024-05-30 15:14:01
  208. // @param condition string
  209. // @param pars []interface{}
  210. // @return count int
  211. // @return err error
  212. func GetReportListCountByGrant(condition string, pars []interface{}) (count int, err error) {
  213. sql := `SELECT a.id FROM report as a
  214. JOIN report_grant b on a.id=b.report_id
  215. WHERE 1=1 `
  216. if condition != "" {
  217. sql += condition
  218. }
  219. sql += " GROUP BY a.id "
  220. sql = `SELECT COUNT(1) AS count FROM (` + sql + `) d`
  221. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  222. return
  223. }
  224. // GetReportListByGrant
  225. // @Description: 获取共享报告列表的数据
  226. // @author: Roc
  227. // @datetime 2024-05-30 15:15:07
  228. // @param condition string
  229. // @param pars []interface{}
  230. // @param startSize int
  231. // @param pageSize int
  232. // @return items []*ReportList
  233. // @return err error
  234. func GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  235. sql := `SELECT a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,a.create_time,a.modify_time,a.state,a.publish_time,a.pre_publish_time,a.stage,a.msg_is_send,a.pre_msg_send,a.video_url,a.video_name,a.video_play_seconds,a.report_code,a.video_size,a.report_version,a.ths_msg_is_send,a.has_chapter,a.chapter_type,a.old_report_id,a.msg_send_time,a.admin_id,a.admin_real_name,a.approve_time,a.approve_id,a.detail_img_url,a.detail_pdf_url,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.canvas_color,a.need_splice,a.head_resource_id,a.end_resource_id,a.classify_id_third,a.classify_name_third,a.collaborate_type,a.report_layout,a.is_public_publish,a.report_create_time,a.inherit_report_id,a.voice_generate_type FROM report as a JOIN report_grant b on a.id = b.report_id WHERE 1=1 `
  236. if condition != "" {
  237. sql += condition
  238. }
  239. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  240. sql += ` GROUP BY a.id,a.add_type,a.classify_id_first,a.classify_name_first,a.classify_id_second,a.classify_name_second,a.title,a.abstract,a.author,a.frequency,a.create_time,a.modify_time,a.state,a.publish_time,a.pre_publish_time,a.stage,a.msg_is_send,a.pre_msg_send,a.video_url,a.video_name,a.video_play_seconds,a.report_code,a.video_size,a.report_version,a.ths_msg_is_send,a.has_chapter,a.chapter_type,a.old_report_id,a.msg_send_time,a.admin_id,a.admin_real_name,a.approve_time,a.approve_id,a.detail_img_url,a.detail_pdf_url,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.canvas_color,a.need_splice,a.head_resource_id,a.end_resource_id,a.classify_id_third,a.classify_name_third,a.collaborate_type,a.report_layout,a.is_public_publish,a.report_create_time,a.inherit_report_id,a.voice_generate_type
  241. ORDER BY CASE a."state"
  242. WHEN 3 THEN 1
  243. WHEN 1 THEN 2
  244. WHEN 4 THEN 3
  245. WHEN 5 THEN 4
  246. WHEN 6 THEN 5
  247. ELSE 6
  248. END, a.modify_time DESC LIMIT ?,?`
  249. pars = append(pars, startSize)
  250. pars = append(pars, pageSize)
  251. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  252. return
  253. }
  254. func GetReportListCount(condition string, pars []interface{}) (count int, err error) {
  255. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 `
  256. if condition != "" {
  257. sql += condition
  258. }
  259. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  260. return
  261. }
  262. // PublishCancelReport 取消发布报告
  263. func PublishCancelReport(reportId, state int, publishTimeNullFlag bool, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  264. var sql string
  265. if publishTimeNullFlag {
  266. 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 =?`
  267. } else {
  268. 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 =?`
  269. }
  270. err = global.DmSQL["rddp"].Exec(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Error
  271. return
  272. }
  273. // 删除报告
  274. func DeleteReport(reportIds int) (err error) {
  275. sql := ` DELETE FROM report WHERE id =? `
  276. err = global.DmSQL["rddp"].Exec(sql, reportIds).Error
  277. return
  278. }
  279. type ReportDetail struct {
  280. Id int `gorm:"column:id;primary_key;autoIncrement" description:"报告Id"`
  281. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  282. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  283. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  284. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  285. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  286. Title string `gorm:"column:title" description:"标题"`
  287. Abstract string `gorm:"column:abstract" description:"摘要"`
  288. Author string `gorm:"column:author" description:"作者"`
  289. Frequency string `gorm:"column:frequency" description:"频度"`
  290. CreateTime string `gorm:"column:create_time" description:"创建时间"`
  291. ModifyTime string `gorm:"column:modify_time" description:"修改时间"`
  292. State int `gorm:"column:state" description:"1:未发布,2:已发布"`
  293. PublishTime string `gorm:"column:publish_time" description:"发布时间"`
  294. PrePublishTime string `gorm:"column:pre_publish_time" description:"预发布时间"`
  295. Stage int `gorm:"column:stage" description:"期数"`
  296. MsgIsSend int `gorm:"column:msg_is_send" description:"消息是否已发送,0:否,1:是"`
  297. PreMsgSend int `gorm:"column:pre_msg_send" description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  298. Content string `gorm:"column:content" description:"内容"`
  299. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  300. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  301. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  302. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  303. ThsMsgIsSend int `gorm:"column:ths_msg_is_send" description:"客户群消息是否已发送,0:否,1:是"`
  304. HasChapter int `gorm:"column:has_chapter" description:"是否有章节 0-否 1-是"`
  305. ChapterType string `gorm:"column:chapter_type" description:"章节类型 day-晨报 week-周报"`
  306. AdminId int `gorm:"column:admin_id" description:"创建者账号"`
  307. AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
  308. ReportCode string `gorm:"column:report_code" description:"报告唯一编码"`
  309. // eta1.8.3(研报改版)相关内容
  310. ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
  311. LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
  312. LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
  313. ContentModifyTime string `gorm:"column:content_modify_time" description:"内容更新时间"`
  314. Pv int `gorm:"column:pv" description:"pv"`
  315. Uv int `gorm:"column:uv" description:"uv"`
  316. HeadImg string `gorm:"column:head_img" description:"报告头图地址"`
  317. EndImg string `gorm:"column:end_img" description:"报告尾图地址"`
  318. HeadStyle string `gorm:"column:head_style" description:"版头样式"`
  319. EndStyle string `gorm:"column:end_style" description:"版尾样式"`
  320. CanvasColor string `gorm:"column:canvas_color" description:"画布颜色"`
  321. NeedSplice int `gorm:"column:need_splice" description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  322. HeadResourceId int `gorm:"column:head_resource_id" description:"版头资源ID"`
  323. EndResourceId int `gorm:"column:end_resource_id" description:"版尾资源ID"`
  324. ClassifyIdThird int `gorm:"column:classify_id_third" description:"三级分类id"`
  325. ClassifyNameThird string `gorm:"column:classify_name_third" description:"三级分类名称"`
  326. CollaborateType int8 `gorm:"column:collaborate_type" description:"协作方式,1:个人,2:多人协作。默认:1"`
  327. ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  328. IsPublicPublish int8 `gorm:"column:is_public_publish" description:"是否公开发布,1:是,2:否"`
  329. ReportCreateTime string `gorm:"column:report_create_time" description:"报告时间创建时间"`
  330. }
  331. func GetReportById(reportId int) (item *ReportDetail, err error) {
  332. reportInfo, err := GetReportByReportId(reportId)
  333. if err != nil {
  334. return
  335. }
  336. item, err = convertReportToReportDetail(*reportInfo)
  337. return
  338. }
  339. func convertReportToReportDetail(report Report) (*ReportDetail, error) {
  340. jsonBytes, err := json.Marshal(report)
  341. if err != nil {
  342. return nil, fmt.Errorf("failed to marshal input: %w", err)
  343. }
  344. reportDetail := new(ReportDetail)
  345. err = json.Unmarshal(jsonBytes, reportDetail)
  346. if err != nil {
  347. return nil, fmt.Errorf("failed to unmarshal input: %w", err)
  348. }
  349. // 对于时间类型的字段,需要转换为字符串
  350. reportDetail.CreateTime = report.CreateTime.Format(utils.FormatDateTime)
  351. reportDetail.ModifyTime = report.ModifyTime.Format(utils.FormatDateTime)
  352. if !report.PublishTime.IsZero() {
  353. reportDetail.PublishTime = report.PublishTime.Format(utils.FormatDateTime)
  354. } else {
  355. reportDetail.PublishTime = ``
  356. }
  357. if !report.ContentModifyTime.IsZero() {
  358. reportDetail.ContentModifyTime = report.ContentModifyTime.Format(utils.FormatDateTime)
  359. } else {
  360. reportDetail.ContentModifyTime = ``
  361. }
  362. if !report.ReportCreateTime.IsZero() {
  363. reportDetail.ReportCreateTime = report.ReportCreateTime.Format(utils.FormatDateTime)
  364. } else {
  365. reportDetail.ReportCreateTime = ``
  366. }
  367. return reportDetail, nil
  368. }
  369. // GetSimpleReportByIds 根据报告ID查询报告基本信息
  370. func GetSimpleReportByIds(reportIds []int) (list []*Report, err error) {
  371. if len(reportIds) == 0 {
  372. return
  373. }
  374. sql := `SELECT id, title, report_code FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  375. err = global.DmSQL["rddp"].Raw(sql, reportIds).Find(&list).Error
  376. return
  377. }
  378. // GetReportStage
  379. // @Description: 获取报告的最大期数(每一年的最大期数)
  380. // @author: Roc
  381. // @datetime 2024-06-03 17:44:14
  382. // @param classifyIdFirst int
  383. // @param classifyIdSecond int
  384. // @param classifyIdThird int
  385. // @return count int
  386. // @return err error
  387. func GetReportStage(classifyIdFirst, classifyIdSecond, classifyIdThird int) (count int, err error) {
  388. classifyId := classifyIdThird
  389. if classifyId <= 0 {
  390. classifyId = classifyIdSecond
  391. }
  392. if classifyId <= 0 {
  393. classifyId = classifyIdFirst
  394. }
  395. if classifyId <= 0 {
  396. err = errors.New("错误的分类id")
  397. return
  398. }
  399. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  400. sql := `SELECT COALESCE(MAX(stage),0) AS count FROM report WHERE create_time > ? `
  401. if classifyIdThird > 0 {
  402. sql += " AND classify_id_third = ? "
  403. } else if classifyIdSecond > 0 {
  404. sql += " AND classify_id_second = ? "
  405. } else {
  406. sql += " AND classify_id_first = ? "
  407. }
  408. err = global.DmSQL["rddp"].Raw(sql, yearStart, classifyId).Scan(&count).Error
  409. return
  410. }
  411. type PublishReq struct {
  412. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  413. ReportUrl string `description:"报告Url"`
  414. }
  415. type PublishCancelReq struct {
  416. ReportIds int `description:"报告id"`
  417. }
  418. type DeleteReq struct {
  419. ReportIds int `description:"报告id"`
  420. }
  421. type AddReq struct {
  422. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  423. ClassifyIdFirst int `description:"一级分类id"`
  424. ClassifyNameFirst string `description:"一级分类名称"`
  425. ClassifyIdSecond int `description:"二级分类id"`
  426. ClassifyNameSecond string `description:"二级分类名称"`
  427. ClassifyIdThird int `description:"三级分类id"`
  428. ClassifyNameThird string `description:"三级分类名称"`
  429. Title string `description:"标题"`
  430. Abstract string `description:"摘要"`
  431. Author string `description:"作者"`
  432. Frequency string `description:"频度"`
  433. State int `description:"状态:1:未发布,2:已发布"`
  434. Content string `description:"内容"`
  435. CreateTime string `description:"创建时间"`
  436. ReportVersion int `description:"1:旧版,2:新版"`
  437. ContentStruct string `description:"内容组件"`
  438. HeadImg string `description:"报告头图地址"`
  439. EndImg string `description:"报告尾图地址"`
  440. CanvasColor string `description:"画布颜色"`
  441. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  442. HeadResourceId int `description:"版头资源ID"`
  443. EndResourceId int `description:"版尾资源ID"`
  444. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  445. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  446. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  447. InheritReportId int `description:"待继承的报告ID"`
  448. GrantAdminIdList []int `description:"授权用户id列表"`
  449. }
  450. type PrePublishReq struct {
  451. ReportId int `description:"报告id"`
  452. PrePublishTime string `description:"预发布时间"`
  453. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  454. ReportUrl string `description:"报告Url"`
  455. }
  456. type AddResp struct {
  457. ReportId int64 `description:"报告id"`
  458. ReportCode string `description:"报告code"`
  459. }
  460. type EditReq struct {
  461. ReportId int64 `description:"报告id"`
  462. ClassifyIdFirst int `description:"一级分类id"`
  463. ClassifyNameFirst string `description:"一级分类名称"`
  464. ClassifyIdSecond int `description:"二级分类id"`
  465. ClassifyNameSecond string `description:"二级分类名称"`
  466. ClassifyIdThird int `description:"三级分类id"`
  467. ClassifyNameThird string `description:"三级分类名称"`
  468. Title string `description:"标题"`
  469. Abstract string `description:"摘要"`
  470. Author string `description:"作者"`
  471. Frequency string `description:"频度"`
  472. State int `description:"状态:1:未发布,2:已发布"`
  473. Content string `description:"内容"`
  474. CreateTime string `description:"创建时间"`
  475. ContentStruct string `description:"内容组件"`
  476. HeadImg string `description:"报告头图地址"`
  477. EndImg string `description:"报告尾图地址"`
  478. CanvasColor string `description:"画布颜色"`
  479. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  480. HeadResourceId int `description:"版头资源ID"`
  481. EndResourceId int `description:"版尾资源ID"`
  482. //CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  483. //ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  484. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  485. GrantAdminIdList []int `description:"授权用户id列表"`
  486. }
  487. type EditResp struct {
  488. ReportId int64 `description:"报告id"`
  489. ReportCode string `description:"报告code"`
  490. }
  491. func EditReport(item *Report, reportId int64) (err error) {
  492. sql := `UPDATE report
  493. SET
  494. classify_id_first =?,
  495. classify_name_first = ?,
  496. classify_id_second = ?,
  497. classify_name_second = ?,
  498. title = ?,
  499. abstract = ?,
  500. author = ?,
  501. frequency = ?,
  502. state = ?,
  503. content = ?,
  504. content_sub = ?,
  505. stage =?,
  506. create_time = ?,
  507. modify_time = ?
  508. WHERE id = ? `
  509. err = global.DmSQL["rddp"].Exec(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  510. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Error
  511. return
  512. }
  513. func (m *Report) Update(cols []string) (err error) {
  514. err = global.DmSQL["rddp"].Select(cols).Updates(m).Error
  515. return
  516. }
  517. type ReportDetailReq struct {
  518. ReportId int `description:"报告id"`
  519. }
  520. type ClassifyIdDetailReq struct {
  521. ClassifyIdFirst int `description:"报告一级分类id"`
  522. ClassifyIdSecond int `description:"报告二级分类id"`
  523. }
  524. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  525. sql := ` SELECT * FROM report WHERE 1=1 `
  526. if classifyIdSecond > 0 {
  527. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  528. err = global.DmSQL["rddp"].Raw(sql, classifyIdSecond).First(&item).Error
  529. } else {
  530. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  531. err = global.DmSQL["rddp"].Raw(sql, classifyIdFirst).First(&item).Error
  532. }
  533. return
  534. }
  535. type SendTemplateMsgReq struct {
  536. ReportId int `description:"报告id"`
  537. }
  538. // SendTemplateMsgResp
  539. // @Description: 报告推送返回结构体
  540. type SendTemplateMsgResp struct {
  541. ReportId int `description:"报告id"`
  542. MsgSendTime string `description:"报告推送时间"`
  543. }
  544. func ModifyReportMsgIsSend(reportId int) (err error) {
  545. report, err := GetReportById(reportId)
  546. if err != nil {
  547. return
  548. }
  549. if report.MsgIsSend == 0 {
  550. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  551. err = global.DmSQL["rddp"].Exec(sql, reportId).Error
  552. }
  553. return
  554. }
  555. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  556. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  557. err = global.DmSQL["rddp"].Exec(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Error
  558. return
  559. }
  560. // ModifyReportVideoByNoVideo
  561. // @Description: 修改无音频的报告音频信息
  562. // @author: Roc
  563. // @datetime 2024-07-25 18:03:05
  564. // @param reportId int
  565. // @param videoUrl string
  566. // @param videoName string
  567. // @param videoSize string
  568. // @param playSeconds float64
  569. // @return err error
  570. func ModifyReportVideoByNoVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  571. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? AND video_url=''`
  572. err = global.DmSQL["rddp"].Exec(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Error
  573. return
  574. }
  575. type ReportItem struct {
  576. gorm.Model
  577. Id int `gorm:"column:id;primary_key;autoIncrement" description:"报告Id"`
  578. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  579. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  580. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  581. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  582. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  583. Title string `gorm:"column:title" description:"标题"`
  584. Abstract string `gorm:"column:abstract" description:"摘要"`
  585. Author string `gorm:"column:author" description:"作者"`
  586. Frequency string `gorm:"column:frequency" description:"频度"`
  587. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  588. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  589. State int `gorm:"column:state" description:"1:未发布,2:已发布"`
  590. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  591. Stage int `gorm:"column:stage" description:"期数"`
  592. MsgIsSend int `gorm:"column:msg_is_send" description:"消息是否已发送,0:否,1:是"`
  593. Content string `gorm:"column:content" description:"内容"`
  594. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  595. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  596. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  597. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  598. }
  599. type SaveReportContent struct {
  600. Content string `description:"内容"`
  601. ReportId int `description:"报告id"`
  602. NoChange int `description:"内容是否未改变:1:内容未改变"`
  603. // 以下是智能研报相关
  604. ContentStruct string `description:"内容组件"`
  605. HeadImg string `description:"报告头图地址"`
  606. EndImg string `description:"报告尾图地址"`
  607. CanvasColor string `description:"画布颜色"`
  608. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  609. HeadResourceId int `description:"版头资源ID"`
  610. EndResourceId int `description:"版尾资源ID"`
  611. }
  612. func AddReportSaveLog(reportId, adminId int, content, contentSub, contentStruct, canvasColor, adminName string, headResourceId, endResourceId int) (err error) {
  613. 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 (?,?,?,?,?,?,?,?,?) `
  614. err = global.DmSQL["rddp"].Exec(sql, reportId, content, contentSub, contentStruct, canvasColor, headResourceId, endResourceId, adminId, adminName).Error
  615. return
  616. }
  617. func MultiAddReportChaptersSaveLog(items []*ReportChapter, adminId int, adminRealName string) (err error) {
  618. tx := global.DmSQL["rddp"].Begin()
  619. for _, v := range items {
  620. err = tx.Exec(`INSERT INTO report_save_log(report_id, report_chapter_id, content, content_sub,content_struct,admin_id, admin_name) VALUES (?,?,?,?,?,?,?)`, v.ReportId, v.ReportChapterId, v.Content, v.ContentSub, v.ContentStruct, adminId, adminRealName).Error
  621. if err != nil {
  622. tx.Rollback()
  623. return
  624. }
  625. }
  626. tx.Commit()
  627. return
  628. }
  629. type SaveReportContentResp struct {
  630. ReportId int `description:"报告id"`
  631. }
  632. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  633. sql := `UPDATE report SET report_code=? WHERE id=? `
  634. err = global.DmSQL["rddp"].Exec(sql, reportCode, reportId).Error
  635. return
  636. }
  637. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  638. if item.ThsMsgIsSend == 0 {
  639. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  640. err = global.DmSQL["rddp"].Exec(sql, item.Id).Error
  641. }
  642. return
  643. }
  644. type ThsSendTemplateMsgReq struct {
  645. ReportId []int `description:"报告id"`
  646. }
  647. type PublishDayWeekReportReq struct {
  648. ReportId int `description:"报告ID"`
  649. }
  650. // SaveDayWeekReportReq 新增晨报周报请求体
  651. type SaveDayWeekReportReq struct {
  652. ReportId int `description:"报告ID"`
  653. Title string `description:"标题"`
  654. ReportType string `description:"一级分类ID"`
  655. Author string `description:"作者"`
  656. CreateTime string `description:"创建时间"`
  657. }
  658. // GetReportByReportId 主键获取报告
  659. func GetReportByReportId(reportId int) (item *Report, err error) {
  660. sql := `SELECT * FROM report WHERE id = ?`
  661. err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
  662. return
  663. }
  664. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  665. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  666. to := global.DmSQL["rddp"].Begin()
  667. defer func() {
  668. if err != nil {
  669. _ = to.Rollback()
  670. } else {
  671. _ = to.Commit()
  672. }
  673. }()
  674. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  675. if err = to.Exec(sql, reportId).Error; err != nil {
  676. return
  677. }
  678. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  679. if err = to.Exec(sql, reportId).Error; err != nil {
  680. return
  681. }
  682. return
  683. }
  684. // UpdateReport 更新报告
  685. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  686. err = global.DmSQL["rddp"].Select(cols).Updates(reportInfo).Error
  687. return
  688. }
  689. // ReportDetailView
  690. // @Description: 晨周报详情
  691. type ReportDetailView struct {
  692. *ReportDetail
  693. ChapterList []*ReportChapter
  694. GrandAdminList []ReportDetailViewAdmin
  695. PermissionList []ReportDetailViewPermission
  696. }
  697. // ReportDetailViewAdmin
  698. // @Description: 报告里面的授权人
  699. type ReportDetailViewAdmin struct {
  700. AdminId int
  701. AdminName string
  702. }
  703. // ReportDetailViewPermission
  704. // @Description: 报告分类关联的品种权限
  705. type ReportDetailViewPermission struct {
  706. PermissionId int
  707. PermissionName string
  708. }
  709. type ElasticReportDetail struct {
  710. gorm.Model
  711. ReportId int `gorm:"column:report_id;index" description:"报告ID"`
  712. ReportChapterId int `gorm:"column:report_chapter_id" description:"报告章节ID"`
  713. Title string `gorm:"column:title" description:"标题"`
  714. Abstract string `gorm:"column:abstract" description:"摘要"`
  715. BodyContent string `gorm:"column:body_content" description:"内容"`
  716. PublishTime string `gorm:"column:publish_time" description:"发布时间"`
  717. PublishState int `gorm:"column:publish_state" description:"发布状态 1-未发布 2-已发布"`
  718. Author string `gorm:"column:author" description:"作者"`
  719. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类ID"`
  720. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  721. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类ID"`
  722. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  723. ClassifyId int `gorm:"column:classify_id" description:"最小单元的分类ID"`
  724. ClassifyName string `gorm:"column:classify_name" description:"最小单元的分类名称"`
  725. Categories string `gorm:"column:categories" description:"关联的品种名称(包括品种别名)"`
  726. StageStr string `gorm:"column:stage_str" description:"报告期数"`
  727. }
  728. // PublishReportAndChapter 发布报告及章节
  729. func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []string) (err error) {
  730. to := global.DmSQL["rddp"].Begin()
  731. defer func() {
  732. if err != nil {
  733. _ = to.Rollback()
  734. } else {
  735. _ = to.Commit()
  736. }
  737. }()
  738. // 更新报告
  739. if isPublishReport {
  740. err = to.Select(cols).Updates(reportInfo).Error
  741. if err != nil {
  742. return
  743. }
  744. }
  745. // 发布该报告的所有章节
  746. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
  747. err = to.Exec(sql, reportInfo.PublishTime, reportInfo.Id).Error
  748. return
  749. }
  750. // PublishReportById 发布报告
  751. func PublishReportById(reportId int, publishTime time.Time, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  752. 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 = ? `
  753. err = global.DmSQL["rddp"].Exec(sql, publishTime, lastModifyAdminId, lastModifyAdminName, reportId).Error
  754. return
  755. }
  756. // ResetReportById 重置报告状态
  757. func ResetReportById(reportId, state int, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  758. 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 = ?`
  759. err = global.DmSQL["rddp"].Exec(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Error
  760. return
  761. }
  762. // 点赞相关的报告列表
  763. type LikeReportItem struct {
  764. gorm.Model
  765. ReportId int `gorm:"column:report_id;index" description:"报告Id"`
  766. ReportChapterId int `gorm:"column:report_chapter_id" description:"报告章节Id"`
  767. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  768. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  769. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  770. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  771. ReportChapterTypeId int `gorm:"column:report_chapter_type_id" description:"章节类型"`
  772. ReportChapterTypeName string `gorm:"column:report_chapter_type_name" description:"品种名称"`
  773. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  774. Title string `gorm:"column:title" description:"标题"`
  775. }
  776. // SunCodeReq 获取太阳码请求体
  777. type SunCodeReq struct {
  778. CodePage string `json:"CodePage" description:"太阳码page"`
  779. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  780. }
  781. // YbPcSuncode 活动海报表
  782. type YbPcSuncode struct {
  783. SuncodeID uint32 `gorm:"column:suncode_id;primaryKey" json:"suncodeId"` //`orm:"column(suncode_id);pk" gorm:"primaryKey" `
  784. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  785. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  786. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  787. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  788. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  789. }
  790. // GetYbPcSunCode 获取太阳码
  791. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  792. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  793. err = global.DmSQL["weekly"].Raw(sql, scene, page).First(&item).Error
  794. return
  795. }
  796. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  797. err = global.DmSQL["weekly"].Create(item).Error
  798. return
  799. }
  800. // YbSuncodePars 小程序太阳码scene参数
  801. type YbSuncodePars struct {
  802. ID uint32 `gorm:"column:id;primaryKey" json:"id"` //`orm:"column(id);pk" gorm:"primaryKey" `
  803. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  804. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  805. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  806. }
  807. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  808. err = global.DmSQL["weekly"].Create(item).Error
  809. return
  810. }
  811. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  812. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  813. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  814. err = global.DmSQL["rddp"].Exec(sql, classifyName, classifyId).Error
  815. return
  816. }
  817. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  818. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  819. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  820. err = global.DmSQL["rddp"].Exec(sql, classifyName, classifyId).Error
  821. return
  822. }
  823. // UpdateReportThirdClassifyNameByClassifyId 更新报告的三级分类名称字段
  824. func UpdateReportThirdClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  825. sql := " UPDATE report SET classify_name_third = ? WHERE classify_id_third = ? "
  826. err = global.DmSQL["rddp"].Exec(sql, classifyName, classifyId).Error
  827. return
  828. }
  829. // ModifyReportAuthor 更改报告作者
  830. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  831. //产品权限
  832. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  833. if condition != "" {
  834. sql += condition
  835. }
  836. result := global.DmSQL["rddp"].Raw(sql, utils.ForwardPars(pars, authorName)...)
  837. count = int(result.RowsAffected)
  838. err = result.Error
  839. return
  840. }
  841. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  842. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  843. err = global.DmSQL["rddp"].Exec(sql1, reportId).Error
  844. if err != nil {
  845. return
  846. }
  847. //修改音频标题
  848. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !='' and video_name is not null)`
  849. err = global.DmSQL["rddp"].Exec(sql2, reportId).Error
  850. return
  851. }
  852. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  853. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  854. err = global.DmSQL["rddp"].Exec(sql1, reportId).Error
  855. if err != nil {
  856. return
  857. }
  858. //修改音频标题
  859. 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)`
  860. err = global.DmSQL["rddp"].Exec(sql2, reportId).Error
  861. return
  862. }
  863. // MarkEditReport 标记编辑英文研报的请求数据
  864. type MarkEditReport struct {
  865. ReportId int `description:"研报id"`
  866. ReportChapterId int `description:"研报章节id"`
  867. Status int `description:"标记状态,1:编辑中,2:查询状态,3:编辑完成"`
  868. }
  869. type MarkReportResp struct {
  870. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  871. Msg string `description:"提示信息"`
  872. Editor string `description:"编辑者姓名"`
  873. }
  874. type MarkReportItem struct {
  875. AdminId int `description:"编辑者ID"`
  876. Editor string `description:"编辑者姓名"`
  877. ReportClassifyNameFirst string
  878. }
  879. // GetReportByCondition 获取报告
  880. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  881. fields := `*`
  882. if len(fieldArr) > 0 {
  883. fields = strings.Join(fieldArr, ",")
  884. }
  885. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  886. sql += condition
  887. order := ` ORDER BY modify_time DESC`
  888. if orderRule != `` {
  889. order = orderRule
  890. }
  891. sql += order
  892. if isPage {
  893. sql += ` LIMIT ?,?`
  894. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  895. } else {
  896. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  897. }
  898. return
  899. }
  900. // SetPrePublishReportById 设置定时发布
  901. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  902. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  903. err = global.DmSQL["rddp"].Exec(sql, prePublishTime, preMsgSend, reportId).Error
  904. return
  905. }
  906. // ReportSubmitApproveReq 提交审批请求体
  907. type ReportSubmitApproveReq struct {
  908. ReportId int `description:"报告ID"`
  909. }
  910. // ReportCancelApproveReq 撤回审批请求体
  911. type ReportCancelApproveReq struct {
  912. ReportId int `description:"报告ID"`
  913. }
  914. func (m *Report) GetItemById(id int) (item *Report, err error) {
  915. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  916. err = global.DmSQL["rddp"].Raw(sql, id).First(&item).Error
  917. return
  918. }
  919. // GetReportStateCount 获取指定状态的报告数量
  920. func GetReportStateCount(state int) (count int, err error) {
  921. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  922. err = global.DmSQL["rddp"].Raw(sql, state).Scan(&count).Error
  923. return
  924. }
  925. // UpdateReportsStateByCond 批量更新报告状态
  926. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, classifyThirdId, oldState, newState int) (err error) {
  927. cond := ``
  928. if classifyFirstId > 0 {
  929. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  930. }
  931. if classifySecondId > 0 {
  932. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  933. }
  934. if classifyThirdId > 0 {
  935. cond += fmt.Sprintf(` AND classify_id_third = %d`, classifyThirdId)
  936. }
  937. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  938. err = global.DmSQL["rddp"].Exec(sql, newState, oldState).Error
  939. return
  940. }
  941. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  942. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  943. if len(secondIds) <= 0 {
  944. return
  945. }
  946. // (有审批流的)未发布->待提交
  947. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  948. err = global.DmSQL["rddp"].Exec(sql, newState, oldState, secondIds).Error
  949. if err != nil {
  950. return
  951. }
  952. // (无审批流的)待提交->未发布
  953. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  954. err = global.DmSQL["rddp"].Exec(sql, oldState, newState, secondIds).Error
  955. return
  956. }
  957. // GetReportPdfUrlReq 获取报告pdf地址请求体
  958. type GetReportPdfUrlReq struct {
  959. ReportUrl string `description:"报告Url"`
  960. ReportCode string `description:"报告Code"`
  961. Type int `description:"类型 1-pdf 2-图片"`
  962. }
  963. func ModifyReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  964. sql := `UPDATE report SET detail_pdf_url=? WHERE id=? `
  965. err = global.DmSQL["rddp"].Exec(sql, detailPdfUrl, reportId).Error
  966. return
  967. }
  968. func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
  969. sql := `UPDATE report SET detail_img_url=? WHERE id=? `
  970. err = global.DmSQL["rddp"].Exec(sql, detailImgUrl, reportId).Error
  971. return
  972. }
  973. // UpdatePdfUrlReportById 清空pdf相关字段
  974. func UpdatePdfUrlReportById(reportId int) (err error) {
  975. sql := `UPDATE report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE id = ? `
  976. err = global.DmSQL["rddp"].Exec(sql, reportId).Error
  977. return
  978. }
  979. // InsertMultiReport
  980. // @Description: 批量新增报告
  981. // @author: Roc
  982. // @datetime 2024-06-27 15:55:25
  983. // @param items []*Report
  984. // @return err error
  985. func InsertMultiReport(items []*Report) (err error) {
  986. err = global.DmSQL["rddp"].CreateInBatches(items, utils.MultiAddNum).Error
  987. return
  988. }
  989. // ReportLayout
  990. // @Description: 报告布局
  991. type ReportLayout struct {
  992. Id int `gorm:"column:id;primaryKey"`
  993. ReportLayout int8 `gorm:"column:report_layout"` //`description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  994. }
  995. // GetReportLayoutByReportId
  996. // @Description: 根据报告id获取报告的布局
  997. // @author: Roc
  998. // @datetime 2024-07-15 15:27:05
  999. // @param reportId int
  1000. // @return item ReportLayout
  1001. // @return err error
  1002. func GetReportLayoutByReportId(reportId int) (item ReportLayout, err error) {
  1003. sql := `SELECT id, report_layout FROM report WHERE id = ? `
  1004. err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
  1005. return
  1006. }
  1007. func GetReportFieldsByIds(ids []int, fields []string) (items []*Report, err error) {
  1008. if len(ids) == 0 {
  1009. return
  1010. }
  1011. field := " * "
  1012. if len(fields) > 0 {
  1013. field = fmt.Sprintf(" %s ", strings.Join(fields, ","))
  1014. }
  1015. sql := fmt.Sprintf(`SELECT %s FROM report WHERE id IN (%s)`, field, utils.GetOrmInReplace(len(ids)))
  1016. err = global.DmSQL["rddp"].Raw(sql, ids).Find(&items).Error
  1017. return
  1018. }
  1019. func (m *Report) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  1020. sql := fmt.Sprintf(`SELECT COUNT(1) FROM report WHERE 1=1 %s`, condition)
  1021. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  1022. return
  1023. }