report.go 57 KB

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