report.go 66 KB

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