report.go 49 KB

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