report.go 54 KB

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