report.go 67 KB

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