report.go 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611
  1. package models
  2. import (
  3. "errors"
  4. "eta_gn/eta_api/global"
  5. "eta_gn/eta_api/utils"
  6. "fmt"
  7. "github.com/beego/beego/v2/client/orm"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. "gorm.io/gorm"
  10. "strings"
  11. "time"
  12. )
  13. // 报告状态
  14. const (
  15. ReportStateUnpublished = 1 // 未发布
  16. ReportStatePublished = 2 // 已发布
  17. ReportStateWaitSubmit = 3 // 待提交
  18. ReportStateWaitApprove = 4 // 审批中
  19. ReportStateRefused = 5 // 已驳回
  20. ReportStatePass = 6 // 已通过
  21. )
  22. // 报告操作
  23. const (
  24. ReportOperateAdd = 1 // 新增报告
  25. ReportOperateEdit = 2 // 编辑报告
  26. ReportOperatePublish = 3 // 发布报告
  27. ReportOperateCancelPublish = 4 // 取消发布报告
  28. ReportOperateSubmitApprove = 5 // 提交审批
  29. ReportOperateCancelApprove = 6 // 撤回审批
  30. )
  31. type Report struct {
  32. Id int `gorm:"column:id;primaryKey;autoIncrement" description:"报告Id"`
  33. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  34. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  35. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  36. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  37. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  38. Title string `gorm:"column:title" description:"标题"`
  39. Abstract string `gorm:"column:abstract" description:"摘要"`
  40. Author string `gorm:"column:author" description:"作者"`
  41. Frequency string `gorm:"column:frequency" description:"频度"`
  42. CreateTime string `gorm:"column:create_time" description:"创建时间"`
  43. ModifyTime time.Time `gorm:"column:modify_time;autoUpdateTime" description:"修改时间"`
  44. State int `gorm:"column:state" description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  45. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  46. Stage int `gorm:"column:stage" description:"期数"`
  47. MsgIsSend int `gorm:"column:msg_is_send" description:"消息是否已发送,0:否,1:是"`
  48. ThsMsgIsSend int `gorm:"column:ths_msg_is_send" description:"客户群消息是否已发送,0:否,1:是"`
  49. Content string `gorm:"column:content" description:"内容"`
  50. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  51. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  52. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  53. VideoSize string `gorm:"column:video_size" description:"音频文件大小,单位M"`
  54. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  55. ReportCode string `gorm:"column:report_code" description:"报告唯一编码"`
  56. ReportVersion int `gorm:"column:report_version" description:"1:旧版,2:新版"`
  57. HasChapter int `gorm:"column:has_chapter" description:"是否有章节 0-否 1-是"`
  58. ChapterType string `gorm:"column:chapter_type" description:"章节类型 day-晨报 week-周报"`
  59. OldReportId int `gorm:"column:old_report_id" description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  60. MsgSendTime time.Time `gorm:"column:msg_send_time" description:"模版消息发送时间"`
  61. AdminId int `gorm:"column:admin_id" description:"创建者账号"`
  62. AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
  63. ApproveTime time.Time `gorm:"column:approve_time" description:"审批时间"`
  64. ApproveId int `gorm:"column:approve_id" description:"审批ID"`
  65. DetailImgUrl string `gorm:"column:detail_img_url" description:"报告详情长图地址"`
  66. DetailPdfUrl string `gorm:"column:detail_pdf_url" description:"报告详情PDF地址"`
  67. ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
  68. LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
  69. LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
  70. ContentModifyTime time.Time `gorm:"column:content_modify_time" description:"内容更新时间"`
  71. Pv int `gorm:"column:pv" description:"pv"`
  72. Uv int `gorm:"column:uv" description:"uv"`
  73. HeadImg string `gorm:"column:head_img" description:"报告头图地址"`
  74. EndImg string `gorm:"column:end_img" description:"报告尾图地址"`
  75. CanvasColor string `gorm:"column:canvas_color" description:"画布颜色"`
  76. NeedSplice int `gorm:"column:need_splice" description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  77. HeadResourceId int `gorm:"column:head_resource_id" description:"版头资源ID"`
  78. EndResourceId int `gorm:"column:end_resource_id" description:"版尾资源ID"`
  79. ClassifyIdThird int `gorm:"column:classify_id_third" description:"三级分类id"`
  80. ClassifyNameThird string `gorm:"column:classify_name_third" description:"三级分类名称"`
  81. CollaborateType int8 `gorm:"column:collaborate_type" description:"协作方式,1:个人,2:多人协作。默认:1"`
  82. ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  83. IsPublicPublish int8 `gorm:"column:is_public_publish" description:"是否公开发布,1:是,2:否"`
  84. ReportCreateTime time.Time `gorm:"column:report_create_time" description:"报告时间创建时间"`
  85. InheritReportId int `gorm:"column:inherit_report_id" description:"待继承的报告ID"`
  86. VoiceGenerateType int `gorm:"column:voice_generate_type" description:"音频生成方式,0:系统生成,1:人工上传"`
  87. }
  88. type ReportList struct {
  89. Id int `gorm:"column:id" description:"报告Id"`
  90. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  91. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  92. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  93. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  94. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  95. Title string `gorm:"column:title" description:"标题"`
  96. Abstract string `gorm:"column:abstract" description:"摘要"`
  97. Author string `gorm:"column:author" description:"作者"`
  98. Frequency string `gorm:"column:frequency" description:"频度"`
  99. CreateTime string `gorm:"column:create_time" description:"创建时间"`
  100. ModifyTime time.Time `gorm:"column:modify_time;autoUpdateTime" description:"修改时间"`
  101. State int `gorm:"column:state" description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  102. PublishTime string `gorm:"column:publish_time" description:"发布时间"`
  103. PrePublishTime string `gorm:"column:pre_publish_time" description:"预发布时间"`
  104. Stage int `gorm:"column:stage" description:"期数"`
  105. MsgIsSend int `gorm:"column:msg_is_send" description:"模板消息是否已发送,0:否,1:是"`
  106. Content string `gorm:"column:content" description:"内容"`
  107. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  108. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  109. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  110. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  111. Pv int `gorm:"column:pv" description:"Pv"`
  112. Uv int `gorm:"column:uv" description:"Uv"`
  113. ReportCode string `gorm:"column:report_code" description:"报告唯一编码"`
  114. ReportVersion int `gorm:"column:report_version" description:"1:旧版,2:新版"`
  115. ThsMsgIsSend int `gorm:"column:ths_msg_is_send" description:"客户群消息是否已发送,0:否,1:是"`
  116. NeedThsMsg int `gorm:"column:need_ths_msg" description:"是否需要推送客群消息 0-否 1-是"`
  117. HasChapter int `gorm:"column:has_chapter" description:"是否有章节 0-否 1-是"`
  118. ChapterType string `gorm:"column:chapter_type" description:"章节类型 day-晨报 week-周报"`
  119. ChapterVideoList []*ReportChapterVideoList `gorm:"-" description:"章节音频列表"` // 不映射到数据库
  120. OldReportId int `gorm:"column:old_report_id" description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  121. MsgSendTime string `gorm:"column:msg_send_time" description:"模版消息发送时间"`
  122. CanEdit bool `gorm:"column:can_edit" description:"是否可编辑"`
  123. HasAuth bool `gorm:"column:has_auth" description:"是否可操作"`
  124. Editor string `gorm:"column:editor" description:"编辑人"`
  125. AdminId int `gorm:"column:admin_id" description:"创建者账号"`
  126. AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
  127. ApproveTime string `gorm:"column:approve_time" description:"审批时间"`
  128. DetailImgUrl string `gorm:"column:detail_img_url" description:"报告详情长图地址"`
  129. DetailPdfUrl string `gorm:"column:detail_pdf_url" description:"报告详情PDF地址"`
  130. CollaborateType int8 `gorm:"column:collaborate_type" description:"协作方式,1:个人,2:多人协作。默认:1"`
  131. ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  132. IsPublicPublish int8 `gorm:"column:is_public_publish" description:"是否公开发布,1:是,2:否"`
  133. ReportCreateTime time.Time `gorm:"column:report_create_time" description:"报告时间创建时间"`
  134. ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
  135. LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
  136. LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
  137. ContentModifyTime time.Time `gorm:"column:content_modify_time" description:"内容更新时间"`
  138. HeadImg string `gorm:"column:head_img" description:"报告头图地址"`
  139. EndImg string `gorm:"column:end_img" description:"报告尾图地址"`
  140. CanvasColor string `gorm:"column:canvas_color" description:"画布颜色"`
  141. NeedSplice int `gorm:"column:need_splice" description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  142. HeadResourceId int `gorm:"column:head_resource_id" description:"版头资源ID"`
  143. EndResourceId int `gorm:"column:end_resource_id" description:"版尾资源ID"`
  144. ClassifyIdThird int `gorm:"column:classify_id_third" description:"三级分类id"`
  145. ClassifyNameThird string `gorm:"column:classify_name_third" description:"三级分类名称"`
  146. InheritReportId int `gorm:"column:inherit_report_id" description:"待继承的报告ID"`
  147. }
  148. type ReportListResp struct {
  149. List []*ReportList
  150. Paging *paging.PagingItem `description:"分页数据"`
  151. }
  152. // GetReportListCountV1
  153. // @Description: 获取普通报告列表的报告数量
  154. // @author: Roc
  155. // @datetime 2024-05-30 15:14:43
  156. // @param condition string
  157. // @param pars []interface{}
  158. // @return count int
  159. // @return err error
  160. func GetReportListCountV1(condition string, pars []interface{}) (count int, err error) {
  161. //o := orm.NewOrmUsingDB("rddp")
  162. sql := `SELECT COUNT(1) AS count FROM report as a WHERE 1=1 `
  163. if condition != "" {
  164. sql += condition
  165. }
  166. //err = o.Raw(sql, pars).QueryRow(&count)
  167. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  168. return
  169. }
  170. // GetReportListV1
  171. // @Description: 获取普通报告列表的数据
  172. // @author: Roc
  173. // @datetime 2024-05-30 15:14:25
  174. // @param condition string
  175. // @param pars []interface{}
  176. // @param startSize int
  177. // @param pageSize int
  178. // @return items []*ReportList
  179. // @return err error
  180. func GetReportListV1(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  181. //o := orm.NewOrmUsingDB("rddp")
  182. sql := `SELECT * FROM report as a WHERE 1=1 `
  183. if condition != "" {
  184. sql += condition
  185. }
  186. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  187. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  188. //_, err = o.Raw(sql, pars...).QueryRows(&items)
  189. pars = append(pars, startSize)
  190. pars = append(pars, pageSize)
  191. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  192. return
  193. }
  194. type ReportPvUv struct {
  195. ReportId int
  196. PvTotal int
  197. UvTotal int
  198. }
  199. func GetReportPvUvByReportIdList(reportIdList []int) (items []ReportPvUv, err error) {
  200. num := len(reportIdList)
  201. if num <= 0 {
  202. return
  203. }
  204. //o := orm.NewOrmUsingDB("rddp")
  205. sql := `SELECT report_id, COUNT(1) as pv_total,COUNT(DISTINCT user_id) as uv_total FROM report_view_record WHERE report_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY report_id`
  206. //_, err = o.Raw(sql, reportIdList).QueryRows(&items)
  207. err = global.DmSQL["rddp"].Raw(sql, reportIdList).Find(&items).Error
  208. return
  209. }
  210. // GetReportListCountByGrant
  211. // @Description: 获取共享报告列表的报告数量
  212. // @author: Roc
  213. // @datetime 2024-05-30 15:14:01
  214. // @param condition string
  215. // @param pars []interface{}
  216. // @return count int
  217. // @return err error
  218. func GetReportListCountByGrant(condition string, pars []interface{}) (count int, err error) {
  219. //o := orm.NewOrmUsingDB("rddp")
  220. sql := `SELECT a.id FROM report as a
  221. JOIN report_grant b on a.id=b.report_id
  222. WHERE 1=1 `
  223. if condition != "" {
  224. sql += condition
  225. }
  226. sql += " GROUP BY a.id "
  227. sql = `SELECT COUNT(1) AS count FROM (` + sql + `) d`
  228. //err = o.Raw(sql, pars).QueryRow(&count)
  229. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  230. return
  231. }
  232. // GetReportListByGrant
  233. // @Description: 获取共享报告列表的数据
  234. // @author: Roc
  235. // @datetime 2024-05-30 15:15:07
  236. // @param condition string
  237. // @param pars []interface{}
  238. // @param startSize int
  239. // @param pageSize int
  240. // @return items []*ReportList
  241. // @return err error
  242. func GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  243. //o := orm.NewOrmUsingDB("rddp")
  244. sql := `SELECT 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.content,a.video_url,a.video_name,a.video_play_seconds,a.content_sub,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.content_struct,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.head_img,a.end_img,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 `
  245. if condition != "" {
  246. sql += condition
  247. }
  248. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  249. 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.content,a.video_url,a.video_name,a.video_play_seconds,a.content_sub,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.content_struct,a.last_modify_admin_id,a.last_modify_admin_name,a.content_modify_time,a.pv,a.uv,a.head_img,a.end_img,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
  250. ORDER BY CASE a."state"
  251. WHEN 3 THEN 1
  252. WHEN 1 THEN 2
  253. WHEN 4 THEN 3
  254. WHEN 5 THEN 4
  255. WHEN 6 THEN 5
  256. ELSE 6
  257. END, a.modify_time DESC LIMIT ?,?`
  258. //_, err = o.Raw(sql, pars...).QueryRows(&items)
  259. pars = append(pars, startSize)
  260. pars = append(pars, pageSize)
  261. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  262. return
  263. }
  264. func GetReportListCount(condition string, pars []interface{}) (count int, err error) {
  265. //oRddp := orm.NewOrmUsingDB("rddp")
  266. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 `
  267. if condition != "" {
  268. sql += condition
  269. }
  270. //err = oRddp.Raw(sql, pars).QueryRow(&count)
  271. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  272. return
  273. }
  274. func GetReportList(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  275. //o := orm.NewOrmUsingDB("rddp")
  276. sql := `SELECT *,
  277. (SELECT COUNT(1) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS pv,
  278. (SELECT COUNT(DISTINCT user_id) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS uv
  279. FROM report WHERE 1=1 `
  280. if condition != "" {
  281. sql += condition
  282. }
  283. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  284. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  285. //_, err = o.Raw(sql, pars...).QueryRows(&items)
  286. pars = append(pars, startSize)
  287. pars = append(pars, pageSize)
  288. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  289. return
  290. }
  291. // PublishReport 发布报告
  292. func PublishReport(reportIds []int) (err error) {
  293. if len(reportIds) == 0 {
  294. return
  295. }
  296. //o := orm.NewOrmUsingDB("rddp")
  297. sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  298. //_, err = o.Raw(sql).Exec()
  299. err = global.DmSQL["rddp"].Exec(sql, reportIds).Error
  300. return
  301. }
  302. // PublishCancelReport 取消发布报告
  303. func PublishCancelReport(reportId, state int, publishTimeNullFlag bool, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  304. //o := orm.NewOrmUsingDB("rddp")
  305. var sql string
  306. if publishTimeNullFlag {
  307. 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 =?`
  308. } else {
  309. 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 =?`
  310. }
  311. // _, err = o.Raw(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Exec()
  312. err = global.DmSQL["rddp"].Exec(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Error
  313. return
  314. }
  315. // 删除报告
  316. func DeleteReport(reportIds int) (err error) {
  317. //o := orm.NewOrmUsingDB("rddp")
  318. sql := ` DELETE FROM report WHERE id =? `
  319. //_, err = o.Raw(sql, reportIds).Exec()
  320. err = global.DmSQL["rddp"].Exec(sql, reportIds).Error
  321. return
  322. }
  323. type ReportDetail struct {
  324. gorm.Model
  325. Id int `gorm:"column:id;primary_key;autoIncrement" description:"报告Id"`
  326. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  327. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  328. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  329. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  330. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  331. Title string `gorm:"column:title" description:"标题"`
  332. Abstract string `gorm:"column:abstract" description:"摘要"`
  333. Author string `gorm:"column:author" description:"作者"`
  334. Frequency string `gorm:"column:frequency" description:"频度"`
  335. CreateTime string `gorm:"column:create_time" description:"创建时间"`
  336. ModifyTime string `gorm:"column:modify_time" description:"修改时间"`
  337. State int `gorm:"column:state" description:"1:未发布,2:已发布"`
  338. PublishTime string `gorm:"column:publish_time" description:"发布时间"`
  339. PrePublishTime string `gorm:"column:pre_publish_time" description:"预发布时间"`
  340. Stage int `gorm:"column:stage" description:"期数"`
  341. MsgIsSend int `gorm:"column:msg_is_send" description:"消息是否已发送,0:否,1:是"`
  342. PreMsgSend int `gorm:"column:pre_msg_send" description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  343. Content string `gorm:"column:content" description:"内容"`
  344. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  345. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  346. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  347. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  348. ThsMsgIsSend int `gorm:"column:ths_msg_is_send" description:"客户群消息是否已发送,0:否,1:是"`
  349. HasChapter int `gorm:"column:has_chapter" description:"是否有章节 0-否 1-是"`
  350. ChapterType string `gorm:"column:chapter_type" description:"章节类型 day-晨报 week-周报"`
  351. AdminId int `gorm:"column:admin_id" description:"创建者账号"`
  352. AdminRealName string `gorm:"column:admin_real_name" description:"创建者姓名"`
  353. ReportCode string `gorm:"column:report_code" description:"报告唯一编码"`
  354. // eta1.8.3(研报改版)相关内容
  355. ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
  356. LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
  357. LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
  358. ContentModifyTime time.Time `gorm:"column:content_modify_time" description:"内容更新时间"`
  359. Pv int `gorm:"column:pv" description:"pv"`
  360. Uv int `gorm:"column:uv" description:"uv"`
  361. HeadImg string `gorm:"column:head_img" description:"报告头图地址"`
  362. EndImg string `gorm:"column:end_img" description:"报告尾图地址"`
  363. HeadStyle string `gorm:"column:head_style" description:"版头样式"`
  364. EndStyle string `gorm:"column:end_style" description:"版尾样式"`
  365. CanvasColor string `gorm:"column:canvas_color" description:"画布颜色"`
  366. NeedSplice int `gorm:"column:need_splice" description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  367. HeadResourceId int `gorm:"column:head_resource_id" description:"版头资源ID"`
  368. EndResourceId int `gorm:"column:end_resource_id" description:"版尾资源ID"`
  369. ClassifyIdThird int `gorm:"column:classify_id_third" description:"三级分类id"`
  370. ClassifyNameThird string `gorm:"column:classify_name_third" description:"三级分类名称"`
  371. CollaborateType int8 `gorm:"column:collaborate_type" description:"协作方式,1:个人,2:多人协作。默认:1"`
  372. ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  373. IsPublicPublish int8 `gorm:"column:is_public_publish" description:"是否公开发布,1:是,2:否"`
  374. ReportCreateTime time.Time `gorm:"column:report_create_time" description:"报告时间创建时间"`
  375. }
  376. func GetReportById(reportId int) (item *ReportDetail, err error) {
  377. //o := orm.NewOrmUsingDB("rddp")
  378. sql := `SELECT * FROM report WHERE id=?`
  379. //err = o.Raw(sql, reportId).QueryRow(&item)
  380. err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
  381. return
  382. }
  383. func GetReportByIds(reportIds string) (list []*ReportDetail, err error) {
  384. //o := orm.NewOrmUsingDB("rddp")
  385. sql := `SELECT * FROM report WHERE id in ` + reportIds
  386. //_, err = o.Raw(sql).QueryRows(&list)
  387. err = global.DmSQL["rddp"].Raw(sql).Find(&list).Error
  388. return
  389. }
  390. // GetSimpleReportByIds 根据报告ID查询报告基本信息
  391. func GetSimpleReportByIds(reportIds []int) (list []*Report, err error) {
  392. if len(reportIds) == 0 {
  393. return
  394. }
  395. //o := orm.NewOrmUsingDB("rddp")
  396. sql := `SELECT id, title, report_code FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  397. //_, err = o.Raw(sql, reportIds).QueryRows(&list)
  398. err = global.DmSQL["rddp"].Raw(sql, reportIds).Find(&list).Error
  399. return
  400. }
  401. // GetReportStage
  402. // @Description: 获取报告的最大期数(每一年的最大期数)
  403. // @author: Roc
  404. // @datetime 2024-06-03 17:44:14
  405. // @param classifyIdFirst int
  406. // @param classifyIdSecond int
  407. // @param classifyIdThird int
  408. // @return count int
  409. // @return err error
  410. func GetReportStage(classifyIdFirst, classifyIdSecond, classifyIdThird int) (count int, err error) {
  411. //o := orm.NewOrmUsingDB("rddp")
  412. classifyId := classifyIdThird
  413. if classifyId <= 0 {
  414. classifyId = classifyIdSecond
  415. }
  416. if classifyId <= 0 {
  417. classifyId = classifyIdFirst
  418. }
  419. if classifyId <= 0 {
  420. err = errors.New("错误的分类id")
  421. return
  422. }
  423. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  424. sql := `SELECT COALESCE(MAX(stage),0) AS count FROM report WHERE create_time > ? `
  425. if classifyIdThird > 0 {
  426. sql += " AND classify_id_third = ? "
  427. } else if classifyIdSecond > 0 {
  428. sql += " AND classify_id_second = ? "
  429. } else {
  430. sql += " AND classify_id_first = ? "
  431. }
  432. //o.Raw(sql, yearStart, classifyId).QueryRow(&count)
  433. err = global.DmSQL["rddp"].Raw(sql, yearStart, classifyId).Scan(&count).Error
  434. return
  435. }
  436. // GetReportStageEdit
  437. // @Description: 获取报告的最大期数(每一年的最大期数)
  438. // @author: Roc
  439. // @datetime 2024-06-04 13:50:34
  440. // @param classifyIdFirst int
  441. // @param classifyIdSecond int
  442. // @param classifyIdThird int
  443. // @param reportId int
  444. // @return count int
  445. // @return err error
  446. func GetReportStageEdit(classifyIdFirst, classifyIdSecond, classifyIdThird, reportId int) (count int, err error) {
  447. classifyId := classifyIdThird
  448. if classifyId <= 0 {
  449. classifyId = classifyIdSecond
  450. }
  451. if classifyId <= 0 {
  452. classifyId = classifyIdFirst
  453. }
  454. if classifyId <= 0 {
  455. err = errors.New("错误的分类id")
  456. return
  457. }
  458. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  459. sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? AND id<>? `
  460. if classifyIdThird > 0 {
  461. sql += " AND classify_id_third = ? "
  462. } else if classifyIdSecond > 0 {
  463. sql += " AND classify_id_second = ? "
  464. } else {
  465. sql = " AND classify_id_first = ? "
  466. }
  467. //o := orm.NewOrmUsingDB("rddp")
  468. //o.Raw(sql, yearStart, reportId, classifyId).QueryRow(&count)
  469. err = global.DmSQL["rddp"].Raw(sql, yearStart, reportId, classifyId).Scan(&count).Error
  470. return
  471. }
  472. type PublishReq struct {
  473. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  474. ReportUrl string `description:"报告Url"`
  475. }
  476. type PublishCancelReq struct {
  477. ReportIds int `description:"报告id"`
  478. }
  479. type DeleteReq struct {
  480. ReportIds int `description:"报告id"`
  481. }
  482. type AddReq struct {
  483. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  484. ClassifyIdFirst int `description:"一级分类id"`
  485. ClassifyNameFirst string `description:"一级分类名称"`
  486. ClassifyIdSecond int `description:"二级分类id"`
  487. ClassifyNameSecond string `description:"二级分类名称"`
  488. ClassifyIdThird int `description:"三级分类id"`
  489. ClassifyNameThird string `description:"三级分类名称"`
  490. Title string `description:"标题"`
  491. Abstract string `description:"摘要"`
  492. Author string `description:"作者"`
  493. Frequency string `description:"频度"`
  494. State int `description:"状态:1:未发布,2:已发布"`
  495. Content string `description:"内容"`
  496. CreateTime string `description:"创建时间"`
  497. ReportVersion int `description:"1:旧版,2:新版"`
  498. ContentStruct string `description:"内容组件"`
  499. HeadImg string `description:"报告头图地址"`
  500. EndImg string `description:"报告尾图地址"`
  501. CanvasColor string `description:"画布颜色"`
  502. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  503. HeadResourceId int `description:"版头资源ID"`
  504. EndResourceId int `description:"版尾资源ID"`
  505. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  506. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  507. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  508. InheritReportId int `description:"待继承的报告ID"`
  509. GrantAdminIdList []int `description:"授权用户id列表"`
  510. }
  511. type PrePublishReq struct {
  512. ReportId int `description:"报告id"`
  513. PrePublishTime string `description:"预发布时间"`
  514. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  515. ReportUrl string `description:"报告Url"`
  516. }
  517. type AddResp struct {
  518. ReportId int64 `description:"报告id"`
  519. ReportCode string `description:"报告code"`
  520. }
  521. func AddReport(item *Report) (lastId int64, err error) {
  522. o := orm.NewOrmUsingDB("rddp")
  523. lastId, err = o.Insert(item)
  524. return
  525. }
  526. type EditReq struct {
  527. ReportId int64 `description:"报告id"`
  528. ClassifyIdFirst int `description:"一级分类id"`
  529. ClassifyNameFirst string `description:"一级分类名称"`
  530. ClassifyIdSecond int `description:"二级分类id"`
  531. ClassifyNameSecond string `description:"二级分类名称"`
  532. ClassifyIdThird int `description:"三级分类id"`
  533. ClassifyNameThird string `description:"三级分类名称"`
  534. Title string `description:"标题"`
  535. Abstract string `description:"摘要"`
  536. Author string `description:"作者"`
  537. Frequency string `description:"频度"`
  538. State int `description:"状态:1:未发布,2:已发布"`
  539. Content string `description:"内容"`
  540. CreateTime string `description:"创建时间"`
  541. ContentStruct string `description:"内容组件"`
  542. HeadImg string `description:"报告头图地址"`
  543. EndImg string `description:"报告尾图地址"`
  544. CanvasColor string `description:"画布颜色"`
  545. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  546. HeadResourceId int `description:"版头资源ID"`
  547. EndResourceId int `description:"版尾资源ID"`
  548. //CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  549. //ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  550. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  551. GrantAdminIdList []int `description:"授权用户id列表"`
  552. }
  553. type EditResp struct {
  554. ReportId int64 `description:"报告id"`
  555. ReportCode string `description:"报告code"`
  556. }
  557. func EditReport(item *Report, reportId int64) (err error) {
  558. //o := orm.NewOrmUsingDB("rddp")
  559. sql := `UPDATE report
  560. SET
  561. classify_id_first =?,
  562. classify_name_first = ?,
  563. classify_id_second = ?,
  564. classify_name_second = ?,
  565. title = ?,
  566. abstract = ?,
  567. author = ?,
  568. frequency = ?,
  569. state = ?,
  570. content = ?,
  571. content_sub = ?,
  572. stage =?,
  573. create_time = ?,
  574. modify_time = ?
  575. WHERE id = ? `
  576. //_, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  577. // item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec()
  578. err = global.DmSQL["rddp"].Exec(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  579. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Error
  580. return
  581. }
  582. func (m *Report) Update(cols []string) (err error) {
  583. //o := orm.NewOrmUsingDB("rddp")
  584. //_, err = o.Update(m, cols...)
  585. err = global.DmSQL["rddp"].Select(cols).Updates(m).Error
  586. return
  587. }
  588. type ReportDetailReq struct {
  589. ReportId int `description:"报告id"`
  590. }
  591. type ClassifyIdDetailReq struct {
  592. ClassifyIdFirst int `description:"报告一级分类id"`
  593. ClassifyIdSecond int `description:"报告二级分类id"`
  594. }
  595. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  596. //o := orm.NewOrmUsingDB("rddp")
  597. sql := ` SELECT * FROM report WHERE 1=1 `
  598. if classifyIdSecond > 0 {
  599. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  600. //err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  601. err = global.DmSQL["rddp"].Raw(sql, classifyIdSecond).First(&item).Error
  602. } else {
  603. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  604. //err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  605. err = global.DmSQL["rddp"].Raw(sql, classifyIdFirst).First(&item).Error
  606. }
  607. return
  608. }
  609. type SendTemplateMsgReq struct {
  610. ReportId int `description:"报告id"`
  611. }
  612. // SendTemplateMsgResp
  613. // @Description: 报告推送返回结构体
  614. type SendTemplateMsgResp struct {
  615. ReportId int `description:"报告id"`
  616. MsgSendTime string `description:"报告推送时间"`
  617. }
  618. func ModifyReportMsgIsSend(reportId int) (err error) {
  619. //o := orm.NewOrmUsingDB("rddp")
  620. report, err := GetReportById(reportId)
  621. if err != nil {
  622. return
  623. }
  624. if report.MsgIsSend == 0 {
  625. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  626. err = global.DmSQL["rddp"].Exec(sql, reportId).Error
  627. //_, err = o.Raw(sql, reportId).Exec()
  628. }
  629. return
  630. }
  631. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  632. //o := orm.NewOrmUsingDB("rddp")
  633. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  634. //_, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  635. err = global.DmSQL["rddp"].Exec(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Error
  636. return
  637. }
  638. // ModifyReportVideoByNoVideo
  639. // @Description: 修改无音频的报告音频信息
  640. // @author: Roc
  641. // @datetime 2024-07-25 18:03:05
  642. // @param reportId int
  643. // @param videoUrl string
  644. // @param videoName string
  645. // @param videoSize string
  646. // @param playSeconds float64
  647. // @return err error
  648. func ModifyReportVideoByNoVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  649. //o := orm.NewOrmUsingDB("rddp")
  650. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? AND video_url=""`
  651. //_, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  652. err = global.DmSQL["rddp"].Exec(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Error
  653. return
  654. }
  655. type ReportItem struct {
  656. gorm.Model
  657. Id int `gorm:"column:id;primary_key;autoIncrement" description:"报告Id"`
  658. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  659. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  660. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  661. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  662. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  663. Title string `gorm:"column:title" description:"标题"`
  664. Abstract string `gorm:"column:abstract" description:"摘要"`
  665. Author string `gorm:"column:author" description:"作者"`
  666. Frequency string `gorm:"column:frequency" description:"频度"`
  667. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  668. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  669. State int `gorm:"column:state" description:"1:未发布,2:已发布"`
  670. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  671. Stage int `gorm:"column:stage" description:"期数"`
  672. MsgIsSend int `gorm:"column:msg_is_send" description:"消息是否已发送,0:否,1:是"`
  673. Content string `gorm:"column:content" description:"内容"`
  674. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  675. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  676. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  677. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  678. }
  679. func GetReportItemById(reportId int) (item *ReportItem, err error) {
  680. //o := orm.NewOrmUsingDB("rddp")
  681. sql := `SELECT * FROM report WHERE id=?`
  682. //err = o.Raw(sql, reportId).QueryRow(&item)
  683. err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
  684. return
  685. }
  686. type SaveReportContent struct {
  687. Content string `description:"内容"`
  688. ReportId int `description:"报告id"`
  689. NoChange int `description:"内容是否未改变:1:内容未改变"`
  690. // 以下是智能研报相关
  691. ContentStruct string `description:"内容组件"`
  692. HeadImg string `description:"报告头图地址"`
  693. EndImg string `description:"报告尾图地址"`
  694. CanvasColor string `description:"画布颜色"`
  695. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  696. HeadResourceId int `description:"版头资源ID"`
  697. EndResourceId int `description:"版尾资源ID"`
  698. }
  699. func EditReportContent(reportId int, content, contentSub string) (err error) {
  700. //o := orm.NewOrmUsingDB("rddp")
  701. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  702. //_, err = o.Raw(sql, content, contentSub, reportId).Exec()
  703. err = global.DmSQL["rddp"].Exec(sql, content, contentSub, reportId).Error
  704. return
  705. }
  706. func AddReportSaveLog(reportId, adminId int, content, contentSub, contentStruct, canvasColor, adminName string, headResourceId, endResourceId int) (err error) {
  707. //o := orm.NewOrmUsingDB("rddp")
  708. 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 (?,?,?,?,?,?,?,?,?) `
  709. //_, err = o.Raw(sql, reportId, content, contentSub, contentStruct, canvasColor, headResourceId, endResourceId, adminId, adminName).Exec()
  710. err = global.DmSQL["rddp"].Exec(sql, reportId, content, contentSub, contentStruct, canvasColor, headResourceId, endResourceId, adminId, adminName).Error
  711. return
  712. }
  713. func MultiAddReportChaptersSaveLog(items []*ReportChapter, adminId int, adminRealName string) (err error) {
  714. //o := orm.NewOrmUsingDB("rddp")
  715. //p, err := o.Raw(`INSERT INTO report_save_log(report_id, report_chapter_id, content, content_sub,content_struct,admin_id, admin_name) VALUES (?,?,?,?,?,?,?)`).Prepare()
  716. //if err != nil {
  717. // return
  718. //}
  719. //defer func() {
  720. // _ = p.Close()
  721. //}()
  722. //for _, v := range items {
  723. // _, err = p.Exec(v.ReportId, v.ReportChapterId, v.Content, v.ContentSub, v.ContentStruct, adminId, adminRealName)
  724. // if err != nil {
  725. // return
  726. // }
  727. //}
  728. tx := global.DmSQL["rddp"].Begin()
  729. for _, v := range items {
  730. 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
  731. if err != nil {
  732. tx.Rollback()
  733. return
  734. }
  735. }
  736. tx.Commit()
  737. return
  738. }
  739. type SaveReportContentResp struct {
  740. ReportId int `description:"报告id"`
  741. }
  742. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  743. //o := orm.NewOrmUsingDB("rddp")
  744. sql := `UPDATE report SET report_code=? WHERE id=? `
  745. //_, err = o.Raw(sql, reportCode, reportId).Exec()
  746. err = global.DmSQL["rddp"].Exec(sql, reportCode, reportId).Error
  747. return
  748. }
  749. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  750. //o := orm.NewOrmUsingDB("rddp")
  751. if item.ThsMsgIsSend == 0 {
  752. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  753. //_, err = o.Raw(sql, item.Id).Exec()
  754. err = global.DmSQL["rddp"].Exec(sql, item.Id).Error
  755. }
  756. return
  757. }
  758. type ThsSendTemplateMsgReq struct {
  759. ReportId []int `description:"报告id"`
  760. }
  761. type PublishDayWeekReportReq struct {
  762. ReportId int `description:"报告ID"`
  763. }
  764. // SaveDayWeekReportReq 新增晨报周报请求体
  765. type SaveDayWeekReportReq struct {
  766. ReportId int `description:"报告ID"`
  767. Title string `description:"标题"`
  768. ReportType string `description:"一级分类ID"`
  769. Author string `description:"作者"`
  770. CreateTime string `description:"创建时间"`
  771. }
  772. // GetDayWeekReportStage 获取晨报周报期数
  773. func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  774. //o := orm.NewOrmUsingDB("rddp")
  775. sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  776. //o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  777. err = global.DmSQL["rddp"].Raw(sql, classifyIdFirst, yearStart).Scan(&count).Error
  778. return
  779. }
  780. // GetReportByReportId 主键获取报告
  781. func GetReportByReportId(reportId int) (item *Report, err error) {
  782. //o := orm.NewOrmUsingDB("rddp")
  783. sql := `SELECT * FROM report WHERE id = ?`
  784. //err = o.Raw(sql, reportId).QueryRow(&item)
  785. err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
  786. return
  787. }
  788. // GetReportByOldReportId 根据老报告id主键获取报告
  789. func GetReportByOldReportId(reportId int) (item *Report, err error) {
  790. //o := orm.NewOrmUsingDB("rddp")
  791. sql := `SELECT * FROM report WHERE old_report_id = ?`
  792. //err = o.Raw(sql, reportId).QueryRow(&item)
  793. err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
  794. return
  795. }
  796. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  797. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  798. //o := orm.NewOrmUsingDB("rddp")
  799. //to, err := o.Begin()
  800. to := global.DmSQL["rddp"].Begin()
  801. defer func() {
  802. if err != nil {
  803. _ = to.Rollback()
  804. } else {
  805. _ = to.Commit()
  806. }
  807. }()
  808. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  809. //if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  810. // return
  811. //}
  812. if err = to.Exec(sql, reportId).Error; err != nil {
  813. return
  814. }
  815. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  816. //if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  817. // return
  818. //}
  819. if err = to.Exec(sql, reportId).Error; err != nil {
  820. return
  821. }
  822. return
  823. }
  824. // UpdateReport 更新报告
  825. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  826. //o := orm.NewOrmUsingDB("rddp")
  827. //_, err = o.Update(reportInfo, cols...)
  828. err = global.DmSQL["rddp"].Select(cols).Updates(reportInfo).Error
  829. return
  830. }
  831. // ReportDetailView
  832. // @Description: 晨周报详情
  833. type ReportDetailView struct {
  834. *ReportDetail
  835. ChapterList []*ReportChapter
  836. GrandAdminList []ReportDetailViewAdmin
  837. PermissionList []ReportDetailViewPermission
  838. }
  839. // ReportDetailViewAdmin
  840. // @Description: 报告里面的授权人
  841. type ReportDetailViewAdmin struct {
  842. AdminId int
  843. AdminName string
  844. }
  845. // ReportDetailViewPermission
  846. // @Description: 报告分类关联的品种权限
  847. type ReportDetailViewPermission struct {
  848. PermissionId int
  849. PermissionName string
  850. }
  851. func GetUnPublishDayReport(startTime time.Time, endTime time.Time) (item *Report, err error) {
  852. //o := orm.NewOrmUsingDB("rddp")
  853. sql := ` SELECT
  854. *
  855. FROM
  856. report AS a
  857. WHERE
  858. a.has_chapter = 1
  859. AND a.chapter_type = "day"
  860. AND a.state = 1
  861. AND (
  862. a.create_time BETWEEN ? AND ?
  863. )
  864. ORDER BY
  865. a.create_time DESC
  866. LIMIT 1 `
  867. //err = o.Raw(sql, startTime, endTime).QueryRow(&item)
  868. err = global.DmSQL["rddp"].Raw(sql, startTime, endTime).First(&item).Error
  869. return
  870. }
  871. type ElasticReportDetail struct {
  872. gorm.Model
  873. ReportId int `gorm:"column:report_id;index" description:"报告ID"`
  874. ReportChapterId int `gorm:"column:report_chapter_id" description:"报告章节ID"`
  875. Title string `gorm:"column:title" description:"标题"`
  876. Abstract string `gorm:"column:abstract" description:"摘要"`
  877. BodyContent string `gorm:"column:body_content" description:"内容"`
  878. PublishTime string `gorm:"column:publish_time" description:"发布时间"`
  879. PublishState int `gorm:"column:publish_state" description:"发布状态 1-未发布 2-已发布"`
  880. Author string `gorm:"column:author" description:"作者"`
  881. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类ID"`
  882. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  883. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类ID"`
  884. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  885. ClassifyId int `gorm:"column:classify_id" description:"最小单元的分类ID"`
  886. ClassifyName string `gorm:"column:classify_name" description:"最小单元的分类名称"`
  887. Categories string `gorm:"column:categories" description:"关联的品种名称(包括品种别名)"`
  888. StageStr string `gorm:"column:stage_str" description:"报告期数"`
  889. }
  890. // GetLastPublishedDayWeekReport 获取上一篇已发布的晨周报
  891. func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  892. //o := orm.NewOrmUsingDB("rddp")
  893. sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  894. //err = o.Raw(sql, chapterType).QueryRow(&item)
  895. err = global.DmSQL["rddp"].Raw(sql, chapterType).First(&item).Error
  896. return
  897. }
  898. // GetNewReportExist
  899. func GetNewReportExist(oldReportId int) (item *Report, err error) {
  900. //o := orm.NewOrmUsingDB("rddp")
  901. sql := ` SELECT id FROM report WHERE old_report_id = ? LIMIT 1 `
  902. //err = o.Raw(sql, oldReportId).QueryRow(&item)
  903. err = global.DmSQL["rddp"].Raw(sql, oldReportId).First(&item).Error
  904. return
  905. }
  906. // PublishReportAndChapter 发布报告及章节
  907. func PublishReportAndChapter(reportInfo *Report, isPublishReport bool, cols []string) (err error) {
  908. //o := orm.NewOrmUsingDB("rddp")
  909. //to, err := o.Begin()
  910. to := global.DmSQL["rddp"].Begin()
  911. defer func() {
  912. if err != nil {
  913. _ = to.Rollback()
  914. } else {
  915. _ = to.Commit()
  916. }
  917. }()
  918. // 更新报告
  919. if isPublishReport {
  920. // _, err = to.Update(reportInfo, cols...)
  921. err = to.Select(cols).Updates(reportInfo).Error
  922. if err != nil {
  923. return
  924. }
  925. }
  926. // 发布该报告的所有章节
  927. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
  928. //_, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id).Exec()
  929. err = to.Exec(sql, reportInfo.PublishTime, reportInfo.Id).Error
  930. // 发布章节
  931. //if len(publishIds) > 0 {
  932. // sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  933. // _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  934. //}
  935. //if len(unPublishIds) > 0 {
  936. // sql := ` UPDATE report_chapter SET publish_state = 1, publish_time = NULL, is_edit = 0 WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(unPublishIds)) + `) `
  937. // _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  938. //}
  939. return
  940. }
  941. func GetSyncEmptyVideoReport() (list []*Report, err error) {
  942. //o := orm.NewOrmUsingDB("rddp")
  943. sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  944. UNION ALL
  945. SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  946. //_, err = o.Raw(sql).QueryRows(&list)
  947. err = global.DmSQL["rddp"].Raw(sql).Find(&list).Error
  948. return
  949. }
  950. // PublishReportById 发布报告
  951. func PublishReportById(reportId int, publishTime time.Time, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  952. //o := orm.NewOrmUsingDB("rddp")
  953. 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 = ? `
  954. //_, err = o.Raw(sql, publishTime, lastModifyAdminId, lastModifyAdminName, reportId).Exec()
  955. err = global.DmSQL["rddp"].Exec(sql, publishTime, lastModifyAdminId, lastModifyAdminName, reportId).Error
  956. return
  957. }
  958. // ResetReportById 重置报告状态
  959. func ResetReportById(reportId, state int, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  960. //o := orm.NewOrmUsingDB("rddp")
  961. 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 = ?`
  962. //_, err = o.Raw(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Exec()
  963. err = global.DmSQL["rddp"].Exec(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Error
  964. return
  965. }
  966. // GetCommentReportByReportId 查询有留言的报告列表
  967. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  968. //o := orm.NewOrmUsingDB("rddp")
  969. sql := `SELECT
  970. id,
  971. create_time,
  972. title,
  973. classify_name_first,
  974. classify_id_first,
  975. classify_name_second,
  976. classify_id_second,
  977. state,
  978. IF
  979. ( publish_time, publish_time, create_time ) AS publish_time
  980. FROM
  981. report
  982. WHERE
  983. 1=1
  984. `
  985. if condition != "" {
  986. sql += condition
  987. }
  988. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  989. //_, err = o.Raw(sql, pars...).QueryRows(&list)
  990. pars = append(pars, startSize)
  991. pars = append(pars, pageSize)
  992. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&list).Error
  993. return
  994. }
  995. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  996. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  997. //o := orm.NewOrmUsingDB("rddp")
  998. sql := `SELECT
  999. id,
  1000. create_time,
  1001. title,
  1002. classify_name_first,
  1003. classify_id_first,
  1004. classify_name_second,
  1005. classify_id_second,
  1006. state,
  1007. IF
  1008. ( publish_time, publish_time, create_time ) AS publish_time
  1009. FROM
  1010. report
  1011. WHERE
  1012. 1=1
  1013. `
  1014. if condition != "" {
  1015. sql += condition
  1016. }
  1017. if orderBy == `` {
  1018. sql += ` ORDER BY publish_time DESC , title ASC `
  1019. } else {
  1020. sql += orderBy
  1021. }
  1022. sql += ` LIMIT ?,? `
  1023. //_, err = o.Raw(sql, pars...).QueryRows(&list)
  1024. pars = append(pars, startSize)
  1025. pars = append(pars, pageSize)
  1026. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&list).Error
  1027. return
  1028. }
  1029. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  1030. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  1031. //o := orm.NewOrmUsingDB("rddp")
  1032. sql := `SELECT count(*)
  1033. FROM report WHERE 1=1`
  1034. if condition != "" {
  1035. sql += condition
  1036. }
  1037. //err = o.Raw(sql, pars).QueryRow(&total)
  1038. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&total).Error
  1039. return
  1040. }
  1041. // 点赞相关的报告列表
  1042. type LikeReportItem struct {
  1043. gorm.Model
  1044. ReportId int `gorm:"column:report_id;index" description:"报告Id"`
  1045. ReportChapterId int `gorm:"column:report_chapter_id" description:"报告章节Id"`
  1046. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  1047. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  1048. ClassifyIdSecond int `gorm:"column:classify_id_second" description:"二级分类id"`
  1049. ClassifyNameSecond string `gorm:"column:classify_name_second" description:"二级分类名称"`
  1050. ReportChapterTypeId int `gorm:"column:report_chapter_type_id" description:"章节类型"`
  1051. ReportChapterTypeName string `gorm:"column:report_chapter_type_name" description:"品种名称"`
  1052. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  1053. Title string `gorm:"column:title" description:"标题"`
  1054. }
  1055. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  1056. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  1057. //o := orm.NewOrmUsingDB("rddp")
  1058. sql := `( SELECT
  1059. id AS report_id,
  1060. 0 AS report_chapter_id,
  1061. classify_id_first,
  1062. classify_id_second,
  1063. classify_name_first,
  1064. classify_name_second,
  1065. 0 as report_chapter_type_id,
  1066. "" as report_chapter_type_name,
  1067. publish_time,
  1068. title
  1069. FROM
  1070. report
  1071. WHERE
  1072. classify_name_first != "晨报"
  1073. AND classify_name_first != "周报"
  1074. AND id in (` + reportIds + `)
  1075. )
  1076. UNION
  1077. ( SELECT
  1078. report_id,
  1079. report_chapter_id,
  1080. classify_id_first,
  1081. 0 as classify_id_second,
  1082. classify_name_first,
  1083. null as classify_name_second,
  1084. type_id as report_chapter_type_id,
  1085. type_name as report_chapter_type_name,
  1086. publish_time,
  1087. title
  1088. FROM
  1089. report_chapter
  1090. WHERE
  1091. report_chapter_id in (` + chapterIds + `)
  1092. )`
  1093. if orderStr != "" {
  1094. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  1095. } else {
  1096. sql += ` ORDER BY publish_time DESC, report_id Desc`
  1097. }
  1098. sql += ` LIMIT ?,?`
  1099. //_, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  1100. err = global.DmSQL["rddp"].Raw(sql, startSize, pageSize).Find(&list).Error
  1101. return
  1102. }
  1103. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  1104. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  1105. //o := orm.NewOrmUsingDB("rddp")
  1106. sql := `select count(*) from (( SELECT
  1107. id AS report_id,
  1108. 0 AS report_chapter_id,
  1109. classify_id_first,
  1110. classify_id_second,
  1111. classify_name_first,
  1112. classify_name_second,
  1113. 0 as report_chapter_type_id,
  1114. publish_time,
  1115. title
  1116. FROM
  1117. report
  1118. WHERE
  1119. classify_name_first != "晨报"
  1120. AND classify_name_first != "周报"
  1121. AND id in (` + reportIds + `)
  1122. )
  1123. UNION
  1124. ( SELECT
  1125. report_id,
  1126. report_chapter_id,
  1127. classify_id_first,
  1128. 0 as classify_id_second,
  1129. classify_name_first,
  1130. null as classify_name_second,
  1131. type_id as report_chapter_type_id,
  1132. publish_time,
  1133. title
  1134. FROM
  1135. report_chapter
  1136. WHERE
  1137. report_chapter_id in (` + chapterIds + `)
  1138. )) r`
  1139. //err = o.Raw(sql).QueryRow(&total)
  1140. err = global.DmSQL["rddp"].Raw(sql).Scan(&total).Error
  1141. return
  1142. }
  1143. // GetPageReportList 分页获取报告列表
  1144. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  1145. //o := orm.NewOrmUsingDB("rddp")
  1146. sql := `SELECT * FROM report WHERE 1=1 `
  1147. sql += condition
  1148. sql += ` ORDER BY modify_time DESC`
  1149. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1150. //err = o.Raw(totalSql, pars).QueryRow(&total)
  1151. err = global.DmSQL["rddp"].Raw(totalSql, pars...).Scan(&total).Error
  1152. if err != nil {
  1153. return
  1154. }
  1155. sql += ` LIMIT ?,? `
  1156. //_, err = o.Raw(sql, pars...).QueryRows(&items)
  1157. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  1158. return
  1159. }
  1160. // SunCodeReq 获取太阳码请求体
  1161. type SunCodeReq struct {
  1162. CodePage string `json:"CodePage" description:"太阳码page"`
  1163. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  1164. }
  1165. // YbPcSuncode 活动海报表
  1166. type YbPcSuncode struct {
  1167. SuncodeID uint32 `gorm:"column:suncode_id;primaryKey" json:"suncodeId"` //`orm:"column(suncode_id);pk" gorm:"primaryKey" `
  1168. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  1169. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  1170. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  1171. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  1172. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  1173. }
  1174. // GetYbPcSunCode 获取太阳码
  1175. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  1176. //o := orm.NewOrmUsingDB("weekly")
  1177. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  1178. //err = o.Raw(sql, scene, page).QueryRow(&item)
  1179. err = global.DmSQL["weekly"].Raw(sql, scene, page).First(&item).Error
  1180. return
  1181. }
  1182. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  1183. //o := orm.NewOrmUsingDB("weekly")
  1184. //_, err = o.Insert(item)
  1185. err = global.DmSQL["weekly"].Create(item).Error
  1186. return
  1187. }
  1188. // YbSuncodePars 小程序太阳码scene参数
  1189. type YbSuncodePars struct {
  1190. ID uint32 `gorm:"column:id;primaryKey" json:"id"` //`orm:"column(id);pk" gorm:"primaryKey" `
  1191. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  1192. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  1193. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  1194. }
  1195. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  1196. //o := orm.NewOrmUsingDB("weekly")
  1197. //_, err = o.Insert(item)
  1198. err = global.DmSQL["weekly"].Create(item).Error
  1199. return
  1200. }
  1201. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  1202. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1203. //o := orm.NewOrmUsingDB("rddp")
  1204. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  1205. //_, err = o.Raw(sql, classifyName, classifyId).Exec()
  1206. err = global.DmSQL["rddp"].Exec(sql, classifyName, classifyId).Error
  1207. return
  1208. }
  1209. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  1210. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1211. //o := orm.NewOrmUsingDB("rddp")
  1212. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  1213. //_, err = o.Raw(sql, classifyName, classifyId).Exec()
  1214. err = global.DmSQL["rddp"].Exec(sql, classifyName, classifyId).Error
  1215. return
  1216. }
  1217. // UpdateReportThirdClassifyNameByClassifyId 更新报告的三级分类名称字段
  1218. func UpdateReportThirdClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1219. //o := orm.NewOrmUsingDB("rddp")
  1220. sql := " UPDATE report SET classify_name_third = ? WHERE classify_id_third = ? "
  1221. //_, err = o.Raw(sql, classifyName, classifyId).Exec()
  1222. err = global.DmSQL["rddp"].Exec(sql, classifyName, classifyId).Error
  1223. return
  1224. }
  1225. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  1226. func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  1227. //o := orm.NewOrmUsingDB("rddp")
  1228. sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  1229. //_, err = o.Raw(sql, classifyName, newClassifyId, classifyId).Exec()
  1230. err = global.DmSQL["rddp"].Exec(sql, classifyName, newClassifyId, classifyId).Error
  1231. return
  1232. }
  1233. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  1234. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  1235. sql := `SELECT
  1236. r.id,
  1237. r.content,
  1238. r.content_sub
  1239. FROM
  1240. report AS r
  1241. JOIN ppt_v2 AS p ON r.id = p.report_id
  1242. WHERE
  1243. p.report_id > 0 AND r.content_sub = ""`
  1244. //_, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  1245. err = global.DmSQL["rddp"].Raw(sql).Find(&list).Error
  1246. return
  1247. }
  1248. // ModifyReportAuthor 更改报告作者
  1249. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  1250. //产品权限
  1251. //oRddp := orm.NewOrmUsingDB("rddp")
  1252. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  1253. if condition != "" {
  1254. sql += condition
  1255. }
  1256. //err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  1257. //err = global.DmSQL["rddp"].Raw(sql, utils.ForwardPars(pars, authorName)...).Scan(&count).Error
  1258. result := global.DmSQL["rddp"].Raw(sql, utils.ForwardPars(pars, authorName)...)
  1259. count = int(result.RowsAffected)
  1260. err = result.Error
  1261. return
  1262. }
  1263. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  1264. //o := orm.NewOrmUsingDB("rddp")
  1265. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  1266. //_, err = o.Raw(sql1, reportId).Exec()
  1267. err = global.DmSQL["rddp"].Exec(sql1, reportId).Error
  1268. if err != nil {
  1269. return
  1270. }
  1271. //修改音频标题
  1272. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  1273. //_, err = o.Raw(sql2, reportId).Exec()
  1274. err = global.DmSQL["rddp"].Exec(sql2, reportId).Error
  1275. return
  1276. }
  1277. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  1278. //o := orm.NewOrmUsingDB("rddp")
  1279. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  1280. //_, err = o.Raw(sql1, reportId).Exec()
  1281. err = global.DmSQL["rddp"].Exec(sql1, reportId).Error
  1282. if err != nil {
  1283. return
  1284. }
  1285. //修改音频标题
  1286. 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)`
  1287. //_, err = o.Raw(sql2, reportId).Exec()
  1288. err = global.DmSQL["rddp"].Exec(sql2, reportId).Error
  1289. return
  1290. }
  1291. // MarkEditReport 标记编辑英文研报的请求数据
  1292. type MarkEditReport struct {
  1293. ReportId int `description:"研报id"`
  1294. ReportChapterId int `description:"研报章节id"`
  1295. Status int `description:"标记状态,1:编辑中,2:查询状态,3:编辑完成"`
  1296. }
  1297. type MarkReportResp struct {
  1298. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  1299. Msg string `description:"提示信息"`
  1300. Editor string `description:"编辑者姓名"`
  1301. }
  1302. type MarkReportItem struct {
  1303. AdminId int `description:"编辑者ID"`
  1304. Editor string `description:"编辑者姓名"`
  1305. ReportClassifyNameFirst string
  1306. }
  1307. // GetReportByCondition 获取报告
  1308. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  1309. //o := orm.NewOrmUsingDB("rddp")
  1310. fields := `*`
  1311. if len(fieldArr) > 0 {
  1312. fields = strings.Join(fieldArr, ",")
  1313. }
  1314. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  1315. sql += condition
  1316. order := ` ORDER BY modify_time DESC`
  1317. if orderRule != `` {
  1318. order = orderRule
  1319. }
  1320. sql += order
  1321. if isPage {
  1322. sql += ` LIMIT ?,?`
  1323. //_, err = o.Raw(sql, pars...).QueryRows(&items)
  1324. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  1325. } else {
  1326. //_, err = o.Raw(sql, pars).QueryRows(&items)
  1327. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  1328. }
  1329. return
  1330. }
  1331. // ModifyReportMsgIsSendV2 更新报告消息状态
  1332. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  1333. //o := orm.NewOrmUsingDB("rddp")
  1334. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  1335. //_, err = o.Raw(sql, reportId).Exec()
  1336. err = global.DmSQL["rddp"].Exec(sql, reportId).Error
  1337. return
  1338. }
  1339. // SetPrePublishReportById 设置定时发布
  1340. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  1341. //o := orm.NewOrmUsingDB("rddp")
  1342. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  1343. //_, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  1344. err = global.DmSQL["rddp"].Exec(sql, prePublishTime, preMsgSend, reportId).Error
  1345. return
  1346. }
  1347. // ReportSubmitApproveReq 提交审批请求体
  1348. type ReportSubmitApproveReq struct {
  1349. ReportId int `description:"报告ID"`
  1350. }
  1351. // ReportCancelApproveReq 撤回审批请求体
  1352. type ReportCancelApproveReq struct {
  1353. ReportId int `description:"报告ID"`
  1354. }
  1355. func (m *Report) GetItemById(id int) (item *Report, err error) {
  1356. //o := orm.NewOrmUsingDB("rddp")
  1357. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  1358. //err = o.Raw(sql, id).QueryRow(&item)
  1359. err = global.DmSQL["rddp"].Raw(sql, id).First(&item).Error
  1360. return
  1361. }
  1362. // GetReportStateCount 获取指定状态的报告数量
  1363. func GetReportStateCount(state int) (count int, err error) {
  1364. //o := orm.NewOrmUsingDB("rddp")
  1365. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  1366. //err = o.Raw(sql, state).QueryRow(&count)
  1367. err = global.DmSQL["rddp"].Raw(sql, state).Scan(&count).Error
  1368. return
  1369. }
  1370. // UpdateReportsStateByCond 批量更新报告状态
  1371. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, classifyThirdId, oldState, newState int) (err error) {
  1372. //o := orm.NewOrmUsingDB("rddp")
  1373. cond := ``
  1374. if classifyFirstId > 0 {
  1375. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  1376. }
  1377. if classifySecondId > 0 {
  1378. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  1379. }
  1380. if classifyThirdId > 0 {
  1381. cond += fmt.Sprintf(` AND classify_id_third = %d`, classifyThirdId)
  1382. }
  1383. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  1384. //_, err = o.Raw(sql, newState, oldState).Exec()
  1385. err = global.DmSQL["rddp"].Exec(sql, newState, oldState).Error
  1386. return
  1387. }
  1388. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  1389. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  1390. if len(secondIds) <= 0 {
  1391. return
  1392. }
  1393. //o := orm.NewOrmUsingDB("rddp")
  1394. // (有审批流的)未发布->待提交
  1395. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1396. //_, err = o.Raw(sql, newState, oldState, secondIds).Exec()
  1397. err = global.DmSQL["rddp"].Exec(sql, newState, oldState, secondIds).Error
  1398. if err != nil {
  1399. return
  1400. }
  1401. // (无审批流的)待提交->未发布
  1402. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1403. //_, err = o.Raw(sql, oldState, newState, secondIds).Exec()
  1404. err = global.DmSQL["rddp"].Exec(sql, oldState, newState, secondIds).Error
  1405. return
  1406. }
  1407. // GetReportPdfUrlReq 获取报告pdf地址请求体
  1408. type GetReportPdfUrlReq struct {
  1409. ReportUrl string `description:"报告Url"`
  1410. ReportCode string `description:"报告Code"`
  1411. Type int `description:"类型 1-pdf 2-图片"`
  1412. }
  1413. func ModifyReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  1414. //o := orm.NewOrmUsingDB("rddp")
  1415. sql := `UPDATE report SET detail_pdf_url=? WHERE id=? `
  1416. //_, err = o.Raw(sql, detailPdfUrl, reportId).Exec()
  1417. err = global.DmSQL["rddp"].Exec(sql, detailPdfUrl, reportId).Error
  1418. return
  1419. }
  1420. func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
  1421. //o := orm.NewOrmUsingDB("rddp")
  1422. sql := `UPDATE report SET detail_img_url=? WHERE id=? `
  1423. //_, err = o.Raw(sql, detailImgUrl, reportId).Exec()
  1424. err = global.DmSQL["rddp"].Exec(sql, detailImgUrl, reportId).Error
  1425. return
  1426. }
  1427. // UpdatePdfUrlReportById 清空pdf相关字段
  1428. func UpdatePdfUrlReportById(reportId int) (err error) {
  1429. //o := orm.NewOrmUsingDB("rddp")
  1430. sql := `UPDATE report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE id = ? `
  1431. //_, err = o.Raw(sql, reportId).Exec()
  1432. err = global.DmSQL["rddp"].Exec(sql, reportId).Error
  1433. return
  1434. }
  1435. // InsertMultiReport
  1436. // @Description: 批量新增报告
  1437. // @author: Roc
  1438. // @datetime 2024-06-27 15:55:25
  1439. // @param items []*Report
  1440. // @return err error
  1441. func InsertMultiReport(items []*Report) (err error) {
  1442. //o := orm.NewOrmUsingDB("rddp")
  1443. //_, err = o.InsertMulti(500, items)
  1444. err = global.DmSQL["rddp"].CreateInBatches(items, utils.MultiAddNum).Error
  1445. return
  1446. }
  1447. // ReportLayout
  1448. // @Description: 报告布局
  1449. type ReportLayout struct {
  1450. Id int `gorm:"column:id;primaryKey"`
  1451. ReportLayout int8 `gorm:"column:report_layout"` //`description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  1452. }
  1453. // GetReportLayoutByReportId
  1454. // @Description: 根据报告id获取报告的布局
  1455. // @author: Roc
  1456. // @datetime 2024-07-15 15:27:05
  1457. // @param reportId int
  1458. // @return item ReportLayout
  1459. // @return err error
  1460. func GetReportLayoutByReportId(reportId int) (item ReportLayout, err error) {
  1461. //o := orm.NewOrmUsingDB("rddp")
  1462. sql := `SELECT id, report_layout FROM report WHERE id = ? `
  1463. //err = o.Raw(sql, reportId).QueryRow(&item)
  1464. err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
  1465. return
  1466. }
  1467. func GetReportFieldsByIds(ids []int, fields []string) (items []*Report, err error) {
  1468. if len(ids) == 0 {
  1469. return
  1470. }
  1471. //o := orm.NewOrmUsingDB("rddp")
  1472. field := " * "
  1473. if len(fields) > 0 {
  1474. field = fmt.Sprintf(" %s ", strings.Join(fields, ","))
  1475. }
  1476. sql := fmt.Sprintf(`SELECT %s FROM report WHERE id IN (%s)`, field, utils.GetOrmInReplace(len(ids)))
  1477. //_, err = o.Raw(sql, ids).QueryRows(&items)
  1478. err = global.DmSQL["rddp"].Raw(sql, ids).Find(&items).Error
  1479. return
  1480. }