report.go 52 KB

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