report.go 54 KB

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