report.go 63 KB

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