report.go 63 KB

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