report.go 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406
  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. // eta1.8.3(研报改版)相关内容
  323. ContentStruct string `description:"内容组件"`
  324. LastModifyAdminId int `description:"最后更新人ID"`
  325. LastModifyAdminName string `description:"最后更新人姓名"`
  326. ContentModifyTime time.Time `description:"内容更新时间"`
  327. Pv int `description:"pv"`
  328. Uv int `description:"uv"`
  329. HeadImg string `description:"报告头图地址"`
  330. EndImg string `description:"报告尾图地址"`
  331. CanvasColor string `description:"画布颜色"`
  332. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  333. HeadResourceId int `description:"版头资源ID"`
  334. EndResourceId int `description:"版尾资源ID"`
  335. ClassifyIdThird int `description:"三级分类id"`
  336. ClassifyNameThird string `description:"三级分类名称"`
  337. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  338. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  339. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  340. ReportCreateTime time.Time `description:"报告时间创建时间"`
  341. }
  342. func GetReportById(reportId int) (item *ReportDetail, err error) {
  343. o := orm.NewOrmUsingDB("rddp")
  344. sql := `SELECT * FROM report WHERE id=?`
  345. err = o.Raw(sql, reportId).QueryRow(&item)
  346. return
  347. }
  348. func GetReportByIds(reportIds string) (list []*ReportDetail, err error) {
  349. o := orm.NewOrmUsingDB("rddp")
  350. sql := `SELECT * FROM report WHERE id in ` + reportIds
  351. _, err = o.Raw(sql).QueryRows(&list)
  352. return
  353. }
  354. // GetSimpleReportByIds 根据报告ID查询报告基本信息
  355. func GetSimpleReportByIds(reportIds []int) (list []*Report, err error) {
  356. if len(reportIds) == 0 {
  357. return
  358. }
  359. o := orm.NewOrmUsingDB("rddp")
  360. sql := `SELECT id, title, report_code FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  361. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  362. return
  363. }
  364. // GetReportStage
  365. // @Description: 获取报告的最大期数(每一年的最大期数)
  366. // @author: Roc
  367. // @datetime 2024-06-03 17:44:14
  368. // @param classifyIdFirst int
  369. // @param classifyIdSecond int
  370. // @param classifyIdThird int
  371. // @return count int
  372. // @return err error
  373. func GetReportStage(classifyIdFirst, classifyIdSecond, classifyIdThird int) (count int, err error) {
  374. o := orm.NewOrmUsingDB("rddp")
  375. classifyId := classifyIdThird
  376. if classifyId <= 0 {
  377. classifyId = classifyIdSecond
  378. }
  379. if classifyId <= 0 {
  380. classifyId = classifyIdFirst
  381. }
  382. if classifyId <= 0 {
  383. err = errors.New("错误的分类id")
  384. return
  385. }
  386. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  387. sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? `
  388. if classifyIdThird > 0 {
  389. sql += " AND classify_id_third = ? "
  390. } else if classifyIdSecond > 0 {
  391. sql += " AND classify_id_second = ? "
  392. } else {
  393. sql = " AND classify_id_first = ? "
  394. }
  395. o.Raw(sql, yearStart, classifyId).QueryRow(&count)
  396. return
  397. }
  398. // GetReportStageEdit
  399. // @Description: 获取报告的最大期数(每一年的最大期数)
  400. // @author: Roc
  401. // @datetime 2024-06-04 13:50:34
  402. // @param classifyIdFirst int
  403. // @param classifyIdSecond int
  404. // @param classifyIdThird int
  405. // @param reportId int
  406. // @return count int
  407. // @return err error
  408. func GetReportStageEdit(classifyIdFirst, classifyIdSecond, classifyIdThird, reportId int) (count int, err error) {
  409. classifyId := classifyIdThird
  410. if classifyId <= 0 {
  411. classifyId = classifyIdSecond
  412. }
  413. if classifyId <= 0 {
  414. classifyId = classifyIdFirst
  415. }
  416. if classifyId <= 0 {
  417. err = errors.New("错误的分类id")
  418. return
  419. }
  420. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  421. sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? AND id<>? `
  422. if classifyIdThird > 0 {
  423. sql += " AND classify_id_third = ? "
  424. } else if classifyIdSecond > 0 {
  425. sql += " AND classify_id_second = ? "
  426. } else {
  427. sql = " AND classify_id_first = ? "
  428. }
  429. o := orm.NewOrmUsingDB("rddp")
  430. o.Raw(sql, yearStart, reportId, classifyId).QueryRow(&count)
  431. return
  432. }
  433. type PublishReq struct {
  434. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  435. ReportUrl string `description:"报告Url"`
  436. }
  437. type PublishCancelReq struct {
  438. ReportIds int `description:"报告id"`
  439. }
  440. type DeleteReq struct {
  441. ReportIds int `description:"报告id"`
  442. }
  443. type AddReq struct {
  444. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  445. ClassifyIdFirst int `description:"一级分类id"`
  446. ClassifyNameFirst string `description:"一级分类名称"`
  447. ClassifyIdSecond int `description:"二级分类id"`
  448. ClassifyNameSecond string `description:"二级分类名称"`
  449. ClassifyIdThird int `description:"三级分类id"`
  450. ClassifyNameThird string `description:"三级分类名称"`
  451. Title string `description:"标题"`
  452. Abstract string `description:"摘要"`
  453. Author string `description:"作者"`
  454. Frequency string `description:"频度"`
  455. State int `description:"状态:1:未发布,2:已发布"`
  456. Content string `description:"内容"`
  457. CreateTime string `description:"创建时间"`
  458. ReportVersion int `description:"1:旧版,2:新版"`
  459. ContentStruct string `description:"内容组件"`
  460. HeadImg string `description:"报告头图地址"`
  461. EndImg string `description:"报告尾图地址"`
  462. CanvasColor string `description:"画布颜色"`
  463. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  464. HeadResourceId int `description:"版头资源ID"`
  465. EndResourceId int `description:"版尾资源ID"`
  466. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  467. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  468. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  469. InheritReportId int `description:"待继承的报告ID"`
  470. GrantAdminIdList []int `description:"授权用户id列表"`
  471. }
  472. type PrePublishReq struct {
  473. ReportId int `description:"报告id"`
  474. PrePublishTime string `description:"预发布时间"`
  475. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  476. ReportUrl string `description:"报告Url"`
  477. }
  478. type AddResp struct {
  479. ReportId int64 `description:"报告id"`
  480. ReportCode string `description:"报告code"`
  481. }
  482. func AddReport(item *Report) (lastId int64, err error) {
  483. o := orm.NewOrmUsingDB("rddp")
  484. lastId, err = o.Insert(item)
  485. return
  486. }
  487. type EditReq struct {
  488. ReportId int64 `description:"报告id"`
  489. ClassifyIdFirst int `description:"一级分类id"`
  490. ClassifyNameFirst string `description:"一级分类名称"`
  491. ClassifyIdSecond int `description:"二级分类id"`
  492. ClassifyNameSecond string `description:"二级分类名称"`
  493. ClassifyIdThird int `description:"三级分类id"`
  494. ClassifyNameThird string `description:"三级分类名称"`
  495. Title string `description:"标题"`
  496. Abstract string `description:"摘要"`
  497. Author string `description:"作者"`
  498. Frequency string `description:"频度"`
  499. State int `description:"状态:1:未发布,2:已发布"`
  500. Content string `description:"内容"`
  501. CreateTime string `description:"创建时间"`
  502. ContentStruct string `description:"内容组件"`
  503. HeadImg string `description:"报告头图地址"`
  504. EndImg string `description:"报告尾图地址"`
  505. CanvasColor string `description:"画布颜色"`
  506. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  507. HeadResourceId int `description:"版头资源ID"`
  508. EndResourceId int `description:"版尾资源ID"`
  509. //CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  510. //ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  511. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  512. GrantAdminIdList []int `description:"授权用户id列表"`
  513. }
  514. type EditResp struct {
  515. ReportId int64 `description:"报告id"`
  516. ReportCode string `description:"报告code"`
  517. }
  518. func EditReport(item *Report, reportId int64) (err error) {
  519. o := orm.NewOrmUsingDB("rddp")
  520. sql := `UPDATE report
  521. SET
  522. classify_id_first =?,
  523. classify_name_first = ?,
  524. classify_id_second = ?,
  525. classify_name_second = ?,
  526. title = ?,
  527. abstract = ?,
  528. author = ?,
  529. frequency = ?,
  530. state = ?,
  531. content = ?,
  532. content_sub = ?,
  533. stage =?,
  534. create_time = ?,
  535. modify_time = ?
  536. WHERE id = ? `
  537. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  538. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec()
  539. return
  540. }
  541. func (m *Report) Update(cols []string) (err error) {
  542. o := orm.NewOrmUsingDB("rddp")
  543. _, err = o.Update(m, cols...)
  544. return
  545. }
  546. type ReportDetailReq struct {
  547. ReportId int `description:"报告id"`
  548. }
  549. type ClassifyIdDetailReq struct {
  550. ClassifyIdFirst int `description:"报告一级分类id"`
  551. ClassifyIdSecond int `description:"报告二级分类id"`
  552. }
  553. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  554. o := orm.NewOrmUsingDB("rddp")
  555. sql := ` SELECT * FROM report WHERE 1=1 `
  556. if classifyIdSecond > 0 {
  557. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  558. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  559. } else {
  560. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  561. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  562. }
  563. return
  564. }
  565. type SendTemplateMsgReq struct {
  566. ReportId int `description:"报告id"`
  567. }
  568. func ModifyReportMsgIsSend(reportId int) (err error) {
  569. o := orm.NewOrmUsingDB("rddp")
  570. report, err := GetReportById(reportId)
  571. if err != nil {
  572. return
  573. }
  574. if report.MsgIsSend == 0 {
  575. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  576. _, err = o.Raw(sql, reportId).Exec()
  577. }
  578. return
  579. }
  580. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  581. o := orm.NewOrmUsingDB("rddp")
  582. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  583. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  584. return
  585. }
  586. type ReportItem struct {
  587. Id int `orm:"column(id)" description:"报告Id"`
  588. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  589. ClassifyIdFirst int `description:"一级分类id"`
  590. ClassifyNameFirst string `description:"一级分类名称"`
  591. ClassifyIdSecond int `description:"二级分类id"`
  592. ClassifyNameSecond string `description:"二级分类名称"`
  593. Title string `description:"标题"`
  594. Abstract string `description:"摘要"`
  595. Author string `description:"作者"`
  596. Frequency string `description:"频度"`
  597. CreateTime time.Time `description:"创建时间"`
  598. ModifyTime time.Time `description:"修改时间"`
  599. State int `description:"1:未发布,2:已发布"`
  600. PublishTime time.Time `description:"发布时间"`
  601. Stage int `description:"期数"`
  602. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  603. Content string `description:"内容"`
  604. VideoUrl string `description:"音频文件URL"`
  605. VideoName string `description:"音频文件名称"`
  606. VideoPlaySeconds string `description:"音频播放时长"`
  607. ContentSub string `description:"内容前两个章节"`
  608. }
  609. func GetReportItemById(reportId int) (item *ReportItem, err error) {
  610. o := orm.NewOrmUsingDB("rddp")
  611. sql := `SELECT * FROM report WHERE id=?`
  612. err = o.Raw(sql, reportId).QueryRow(&item)
  613. return
  614. }
  615. type SaveReportContent struct {
  616. Content string `description:"内容"`
  617. ReportId int `description:"报告id"`
  618. NoChange int `description:"内容是否未改变:1:内容未改变"`
  619. // 以下是智能研报相关
  620. ContentStruct string `description:"内容组件"`
  621. HeadImg string `description:"报告头图地址"`
  622. EndImg string `description:"报告尾图地址"`
  623. CanvasColor string `description:"画布颜色"`
  624. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  625. HeadResourceId int `description:"版头资源ID"`
  626. EndResourceId int `description:"版尾资源ID"`
  627. }
  628. func EditReportContent(reportId int, content, contentSub string) (err error) {
  629. o := orm.NewOrmUsingDB("rddp")
  630. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  631. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  632. return
  633. }
  634. func AddReportSaveLog(reportId, adminId int, content, contentSub, contentStruct, canvasColor, adminName string, headResourceId, endResourceId int) (err error) {
  635. o := orm.NewOrmUsingDB("rddp")
  636. 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 (?,?,?,?,?) `
  637. _, err = o.Raw(sql, reportId, content, contentSub, contentStruct, canvasColor, headResourceId, endResourceId, adminId, adminName).Exec()
  638. return
  639. }
  640. func MultiAddReportChaptersSaveLog(items []*ReportChapter, adminId int, adminRealName string) (err error) {
  641. o := orm.NewOrmUsingDB("rddp")
  642. p, err := o.Raw(`INSERT INTO report_save_log(report_id, report_chapter_id, content, content_sub,content_struct,canvas_color,head_resource_id,end_resource_id, admin_id, admin_name) VALUES (?,?,?,?,?,?,?,?,?,?)`).Prepare()
  643. if err != nil {
  644. return
  645. }
  646. defer func() {
  647. _ = p.Close()
  648. }()
  649. for _, v := range items {
  650. _, err = p.Exec(v.ReportId, v.ReportChapterId, v.Content, v.ContentSub, v.ContentStruct, v.CanvasColor, v.HeadResourceId, v.EndResourceId, adminId, adminRealName)
  651. if err != nil {
  652. return
  653. }
  654. }
  655. return
  656. }
  657. type SaveReportContentResp struct {
  658. ReportId int `description:"报告id"`
  659. }
  660. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  661. o := orm.NewOrmUsingDB("rddp")
  662. sql := `UPDATE report SET report_code=? WHERE id=? `
  663. _, err = o.Raw(sql, reportCode, reportId).Exec()
  664. return
  665. }
  666. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  667. o := orm.NewOrmUsingDB("rddp")
  668. if item.ThsMsgIsSend == 0 {
  669. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  670. _, err = o.Raw(sql, item.Id).Exec()
  671. }
  672. return
  673. }
  674. type ThsSendTemplateMsgReq struct {
  675. ReportId []int `description:"报告id"`
  676. }
  677. type PublishDayWeekReportReq struct {
  678. ReportId int `description:"报告ID"`
  679. }
  680. // SaveDayWeekReportReq 新增晨报周报请求体
  681. type SaveDayWeekReportReq struct {
  682. ReportId int `description:"报告ID"`
  683. Title string `description:"标题"`
  684. ReportType string `description:"一级分类ID"`
  685. Author string `description:"作者"`
  686. CreateTime string `description:"创建时间"`
  687. }
  688. // GetDayWeekReportStage 获取晨报周报期数
  689. func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  690. o := orm.NewOrmUsingDB("rddp")
  691. sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  692. o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  693. return
  694. }
  695. // GetReportByReportId 主键获取报告
  696. func GetReportByReportId(reportId int) (item *Report, err error) {
  697. o := orm.NewOrmUsingDB("rddp")
  698. sql := `SELECT * FROM report WHERE id = ?`
  699. err = o.Raw(sql, reportId).QueryRow(&item)
  700. return
  701. }
  702. // GetReportByOldReportId 根据老报告id主键获取报告
  703. func GetReportByOldReportId(reportId int) (item *Report, err error) {
  704. o := orm.NewOrmUsingDB("rddp")
  705. sql := `SELECT * FROM report WHERE old_report_id = ?`
  706. err = o.Raw(sql, reportId).QueryRow(&item)
  707. return
  708. }
  709. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  710. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  711. o := orm.NewOrmUsingDB("rddp")
  712. to, err := o.Begin()
  713. if err != nil {
  714. return
  715. }
  716. defer func() {
  717. if err != nil {
  718. _ = to.Rollback()
  719. } else {
  720. _ = to.Commit()
  721. }
  722. }()
  723. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  724. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  725. return
  726. }
  727. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  728. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  729. return
  730. }
  731. return
  732. }
  733. // UpdateReport 更新报告
  734. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  735. o := orm.NewOrmUsingDB("rddp")
  736. _, err = o.Update(reportInfo, cols...)
  737. return
  738. }
  739. // ReportDetailView
  740. // @Description: 晨周报详情
  741. type ReportDetailView struct {
  742. *ReportDetail
  743. ChapterList []*ReportChapter
  744. GrandAdminList []ReportDetailViewAdmin
  745. PermissionList []ReportDetailViewPermission
  746. }
  747. // ReportDetailViewAdmin
  748. // @Description: 报告里面的授权人
  749. type ReportDetailViewAdmin struct {
  750. AdminId int
  751. AdminName string
  752. }
  753. // ReportDetailViewPermission
  754. // @Description: 报告分类关联的品种权限
  755. type ReportDetailViewPermission struct {
  756. PermissionId int
  757. PermissionName string
  758. }
  759. func GetUnPublishDayReport(startTime time.Time, endTime time.Time) (item *Report, err error) {
  760. o := orm.NewOrmUsingDB("rddp")
  761. sql := ` SELECT
  762. *
  763. FROM
  764. report AS a
  765. WHERE
  766. a.has_chapter = 1
  767. AND a.chapter_type = "day"
  768. AND a.state = 1
  769. AND (
  770. a.create_time BETWEEN ? AND ?
  771. )
  772. ORDER BY
  773. a.create_time DESC
  774. LIMIT 1 `
  775. err = o.Raw(sql, startTime, endTime).QueryRow(&item)
  776. return
  777. }
  778. type ElasticReportDetail struct {
  779. ReportId int `description:"报告ID"`
  780. ReportChapterId int `description:"报告章节ID"`
  781. Title string `description:"标题"`
  782. Abstract string `description:"摘要"`
  783. BodyContent string `description:"内容"`
  784. PublishTime string `description:"发布时间"`
  785. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  786. Author string `description:"作者"`
  787. ClassifyIdFirst int `description:"一级分类ID"`
  788. ClassifyNameFirst string `description:"一级分类名称"`
  789. ClassifyIdSecond int `description:"二级分类ID"`
  790. ClassifyNameSecond string `description:"二级分类名称"`
  791. Categories string `description:"关联的品种名称(包括品种别名)"`
  792. StageStr string `description:"报告期数"`
  793. BodyMd5 string `description:"MD5加密之后的内容"`
  794. }
  795. // GetLastPublishedDayWeekReport 获取上一篇已发布的晨周报
  796. func GetLastPublishDayWeekReport(chapterType string) (item *Report, err error) {
  797. o := orm.NewOrmUsingDB("rddp")
  798. sql := ` SELECT * FROM report WHERE has_chapter = 1 AND chapter_type = ? AND state = 2 ORDER BY publish_time DESC LIMIT 1 `
  799. err = o.Raw(sql, chapterType).QueryRow(&item)
  800. return
  801. }
  802. // GetNewReportExist
  803. func GetNewReportExist(oldReportId int) (item *Report, err error) {
  804. o := orm.NewOrmUsingDB("rddp")
  805. sql := ` SELECT id FROM report WHERE old_report_id = ? LIMIT 1 `
  806. err = o.Raw(sql, oldReportId).QueryRow(&item)
  807. return
  808. }
  809. // PublishReportAndChapter 发布报告及章节
  810. func PublishReportAndChapter(reportInfo *Report, publishIds, unPublishIds []int, isPublishReport bool, cols []string) (err error) {
  811. o := orm.NewOrmUsingDB("rddp")
  812. to, err := o.Begin()
  813. if err != nil {
  814. return
  815. }
  816. defer func() {
  817. if err != nil {
  818. _ = to.Rollback()
  819. } else {
  820. _ = to.Commit()
  821. }
  822. }()
  823. // 更新报告
  824. if isPublishReport {
  825. if _, err = to.Update(reportInfo, cols...); err != nil {
  826. return
  827. }
  828. }
  829. // 发布章节
  830. if len(publishIds) > 0 {
  831. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  832. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  833. }
  834. if len(unPublishIds) > 0 {
  835. 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)) + `) `
  836. _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  837. }
  838. return
  839. }
  840. func GetSyncEmptyVideoReport() (list []*Report, err error) {
  841. o := orm.NewOrmUsingDB("rddp")
  842. sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  843. UNION ALL
  844. SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  845. _, err = o.Raw(sql).QueryRows(&list)
  846. return
  847. }
  848. // PublishReportById 发布报告
  849. func PublishReportById(reportId int, publishTime time.Time) (err error) {
  850. o := orm.NewOrmUsingDB("rddp")
  851. sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW() WHERE id = ? `
  852. _, err = o.Raw(sql, publishTime, reportId).Exec()
  853. return
  854. }
  855. // ResetReportById 重置报告状态
  856. func ResetReportById(reportId, state int) (err error) {
  857. o := orm.NewOrmUsingDB("rddp")
  858. sql := `UPDATE report SET state = ?, pre_publish_time = null, pre_msg_send = 0, modify_time = NOW() WHERE id = ?`
  859. _, err = o.Raw(sql, state, reportId).Exec()
  860. return
  861. }
  862. // GetCommentReportByReportId 查询有留言的报告列表
  863. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  864. o := orm.NewOrmUsingDB("rddp")
  865. sql := `SELECT
  866. id,
  867. create_time,
  868. title,
  869. classify_name_first,
  870. classify_id_first,
  871. classify_name_second,
  872. classify_id_second,
  873. state,
  874. IF
  875. ( publish_time, publish_time, create_time ) AS publish_time
  876. FROM
  877. report
  878. WHERE
  879. 1=1
  880. `
  881. if condition != "" {
  882. sql += condition
  883. }
  884. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  885. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  886. return
  887. }
  888. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  889. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  890. o := orm.NewOrmUsingDB("rddp")
  891. sql := `SELECT
  892. id,
  893. create_time,
  894. title,
  895. classify_name_first,
  896. classify_id_first,
  897. classify_name_second,
  898. classify_id_second,
  899. state,
  900. IF
  901. ( publish_time, publish_time, create_time ) AS publish_time
  902. FROM
  903. report
  904. WHERE
  905. 1=1
  906. `
  907. if condition != "" {
  908. sql += condition
  909. }
  910. if orderBy == `` {
  911. sql += ` ORDER BY publish_time DESC , title ASC `
  912. } else {
  913. sql += orderBy
  914. }
  915. sql += ` LIMIT ?,? `
  916. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  917. return
  918. }
  919. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  920. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  921. o := orm.NewOrmUsingDB("rddp")
  922. sql := `SELECT count(*)
  923. FROM report WHERE 1=1`
  924. if condition != "" {
  925. sql += condition
  926. }
  927. err = o.Raw(sql, pars).QueryRow(&total)
  928. return
  929. }
  930. // 点赞相关的报告列表
  931. type LikeReportItem struct {
  932. ReportId int `description:"报告Id"`
  933. ReportChapterId int `description:"报告章节Id"`
  934. ClassifyIdFirst int `description:"一级分类id"`
  935. ClassifyNameFirst string `description:"一级分类名称"`
  936. ClassifyIdSecond int `description:"二级分类id"`
  937. ClassifyNameSecond string `description:"二级分类名称"`
  938. ReportChapterTypeId int `description:"章节类型"`
  939. ReportChapterTypeName string `description:"品种名称"`
  940. PublishTime time.Time `description:"发布时间" `
  941. Title string `description:"标题"`
  942. }
  943. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  944. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  945. o := orm.NewOrmUsingDB("rddp")
  946. sql := `( SELECT
  947. id AS report_id,
  948. 0 AS report_chapter_id,
  949. classify_id_first,
  950. classify_id_second,
  951. classify_name_first,
  952. classify_name_second,
  953. 0 as report_chapter_type_id,
  954. "" as report_chapter_type_name,
  955. publish_time,
  956. title
  957. FROM
  958. report
  959. WHERE
  960. classify_name_first != "晨报"
  961. AND classify_name_first != "周报"
  962. AND id in (` + reportIds + `)
  963. )
  964. UNION
  965. ( SELECT
  966. report_id,
  967. report_chapter_id,
  968. classify_id_first,
  969. 0 as classify_id_second,
  970. classify_name_first,
  971. null as classify_name_second,
  972. type_id as report_chapter_type_id,
  973. type_name as report_chapter_type_name,
  974. publish_time,
  975. title
  976. FROM
  977. report_chapter
  978. WHERE
  979. report_chapter_id in (` + chapterIds + `)
  980. )`
  981. if orderStr != "" {
  982. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  983. } else {
  984. sql += ` ORDER BY publish_time DESC, report_id Desc`
  985. }
  986. sql += ` LIMIT ?,?`
  987. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  988. return
  989. }
  990. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  991. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  992. o := orm.NewOrmUsingDB("rddp")
  993. sql := `select count(*) from (( SELECT
  994. id AS report_id,
  995. 0 AS report_chapter_id,
  996. classify_id_first,
  997. classify_id_second,
  998. classify_name_first,
  999. classify_name_second,
  1000. 0 as report_chapter_type_id,
  1001. publish_time,
  1002. title
  1003. FROM
  1004. report
  1005. WHERE
  1006. classify_name_first != "晨报"
  1007. AND classify_name_first != "周报"
  1008. AND id in (` + reportIds + `)
  1009. )
  1010. UNION
  1011. ( SELECT
  1012. report_id,
  1013. report_chapter_id,
  1014. classify_id_first,
  1015. 0 as classify_id_second,
  1016. classify_name_first,
  1017. null as classify_name_second,
  1018. type_id as report_chapter_type_id,
  1019. publish_time,
  1020. title
  1021. FROM
  1022. report_chapter
  1023. WHERE
  1024. report_chapter_id in (` + chapterIds + `)
  1025. )) r`
  1026. err = o.Raw(sql).QueryRow(&total)
  1027. return
  1028. }
  1029. // GetPageReportList 分页获取报告列表
  1030. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  1031. o := orm.NewOrmUsingDB("rddp")
  1032. sql := `SELECT * FROM report WHERE 1=1 `
  1033. sql += condition
  1034. sql += ` ORDER BY modify_time DESC`
  1035. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1036. err = o.Raw(totalSql, pars).QueryRow(&total)
  1037. if err != nil {
  1038. return
  1039. }
  1040. sql += ` LIMIT ?,? `
  1041. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1042. return
  1043. }
  1044. // SunCodeReq 获取太阳码请求体
  1045. type SunCodeReq struct {
  1046. CodePage string `json:"CodePage" description:"太阳码page"`
  1047. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  1048. }
  1049. // YbPcSuncode 活动海报表
  1050. type YbPcSuncode struct {
  1051. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  1052. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  1053. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  1054. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  1055. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  1056. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  1057. }
  1058. // GetYbPcSunCode 获取太阳码
  1059. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  1060. o := orm.NewOrmUsingDB("weekly")
  1061. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  1062. err = o.Raw(sql, scene, page).QueryRow(&item)
  1063. return
  1064. }
  1065. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  1066. o := orm.NewOrmUsingDB("weekly")
  1067. _, err = o.Insert(item)
  1068. return
  1069. }
  1070. // YbSuncodePars 小程序太阳码scene参数
  1071. type YbSuncodePars struct {
  1072. ID uint32 `orm:"column(id);pk" `
  1073. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  1074. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  1075. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  1076. }
  1077. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  1078. o := orm.NewOrmUsingDB("weekly")
  1079. _, err = o.Insert(item)
  1080. return
  1081. }
  1082. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  1083. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1084. o := orm.NewOrmUsingDB("rddp")
  1085. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  1086. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1087. return
  1088. }
  1089. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  1090. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1091. o := orm.NewOrmUsingDB("rddp")
  1092. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  1093. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1094. return
  1095. }
  1096. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  1097. func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  1098. o := orm.NewOrmUsingDB("rddp")
  1099. sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  1100. _, err = o.Raw(sql, classifyName, newClassifyId, classifyId).Exec()
  1101. return
  1102. }
  1103. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  1104. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  1105. sql := `SELECT
  1106. r.id,
  1107. r.content,
  1108. r.content_sub
  1109. FROM
  1110. report AS r
  1111. JOIN ppt_v2 AS p ON r.id = p.report_id
  1112. WHERE
  1113. p.report_id > 0 AND r.content_sub = ""`
  1114. _, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  1115. return
  1116. }
  1117. // ModifyReportAuthor 更改报告作者
  1118. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  1119. //产品权限
  1120. oRddp := orm.NewOrmUsingDB("rddp")
  1121. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  1122. if condition != "" {
  1123. sql += condition
  1124. }
  1125. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  1126. return
  1127. }
  1128. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  1129. o := orm.NewOrmUsingDB("rddp")
  1130. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  1131. _, err = o.Raw(sql1, reportId).Exec()
  1132. if err != nil {
  1133. return
  1134. }
  1135. //修改音频标题
  1136. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  1137. _, err = o.Raw(sql2, reportId).Exec()
  1138. return
  1139. }
  1140. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  1141. o := orm.NewOrmUsingDB("rddp")
  1142. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  1143. _, err = o.Raw(sql1, reportId).Exec()
  1144. if err != nil {
  1145. return
  1146. }
  1147. //修改音频标题
  1148. 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)`
  1149. _, err = o.Raw(sql2, reportId).Exec()
  1150. return
  1151. }
  1152. // MarkEditReport 标记编辑英文研报的请求数据
  1153. type MarkEditReport struct {
  1154. ReportId int `description:"研报id"`
  1155. ReportChapterId int `description:"研报章节id"`
  1156. Status int `description:"标记状态,1:编辑中,2:编辑完成"`
  1157. }
  1158. type MarkReportResp struct {
  1159. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  1160. Msg string `description:"提示信息"`
  1161. Editor string `description:"编辑者姓名"`
  1162. }
  1163. type MarkReportItem struct {
  1164. AdminId int `description:"编辑者ID"`
  1165. Editor string `description:"编辑者姓名"`
  1166. ReportClassifyNameFirst string
  1167. }
  1168. // GetReportByCondition 获取报告
  1169. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  1170. o := orm.NewOrmUsingDB("rddp")
  1171. fields := `*`
  1172. if len(fieldArr) > 0 {
  1173. fields = strings.Join(fieldArr, ",")
  1174. }
  1175. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  1176. sql += condition
  1177. order := ` ORDER BY modify_time DESC`
  1178. if orderRule != `` {
  1179. order = orderRule
  1180. }
  1181. sql += order
  1182. if isPage {
  1183. sql += ` LIMIT ?,?`
  1184. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1185. } else {
  1186. _, err = o.Raw(sql, pars).QueryRows(&items)
  1187. }
  1188. return
  1189. }
  1190. // ModifyReportMsgIsSendV2 更新报告消息状态
  1191. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  1192. o := orm.NewOrmUsingDB("rddp")
  1193. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  1194. _, err = o.Raw(sql, reportId).Exec()
  1195. return
  1196. }
  1197. // SetPrePublishReportById 设置定时发布
  1198. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  1199. o := orm.NewOrmUsingDB("rddp")
  1200. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  1201. _, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  1202. return
  1203. }
  1204. // ReportSubmitApproveReq 提交审批请求体
  1205. type ReportSubmitApproveReq struct {
  1206. ReportId int `description:"报告ID"`
  1207. }
  1208. // ReportCancelApproveReq 撤回审批请求体
  1209. type ReportCancelApproveReq struct {
  1210. ReportId int `description:"报告ID"`
  1211. }
  1212. func (m *Report) GetItemById(id int) (item *Report, err error) {
  1213. o := orm.NewOrmUsingDB("rddp")
  1214. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  1215. err = o.Raw(sql, id).QueryRow(&item)
  1216. return
  1217. }
  1218. // GetReportStateCount 获取指定状态的报告数量
  1219. func GetReportStateCount(state int) (count int, err error) {
  1220. o := orm.NewOrmUsingDB("rddp")
  1221. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  1222. err = o.Raw(sql, state).QueryRow(&count)
  1223. return
  1224. }
  1225. // UpdateReportsStateByCond 批量更新报告状态
  1226. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, oldState, newState int) (err error) {
  1227. o := orm.NewOrmUsingDB("rddp")
  1228. cond := ``
  1229. if classifyFirstId > 0 {
  1230. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  1231. }
  1232. if classifySecondId > 0 {
  1233. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  1234. }
  1235. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  1236. _, err = o.Raw(sql, newState, oldState).Exec()
  1237. return
  1238. }
  1239. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  1240. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  1241. if len(secondIds) <= 0 {
  1242. return
  1243. }
  1244. o := orm.NewOrmUsingDB("rddp")
  1245. // (有审批流的)未发布->待提交
  1246. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1247. _, err = o.Raw(sql, newState, oldState, secondIds).Exec()
  1248. if err != nil {
  1249. return
  1250. }
  1251. // (无审批流的)待提交->未发布
  1252. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1253. _, err = o.Raw(sql, oldState, newState, secondIds).Exec()
  1254. return
  1255. }
  1256. // GetReportPdfUrlReq 获取报告pdf地址请求体
  1257. type GetReportPdfUrlReq struct {
  1258. ReportUrl string `description:"报告Url"`
  1259. ReportCode string `description:"报告Code"`
  1260. Type int `description:"类型 1-pdf 2-图片"`
  1261. }
  1262. func ModifyReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  1263. o := orm.NewOrmUsingDB("rddp")
  1264. sql := `UPDATE report SET detail_pdf_url=? WHERE id=? `
  1265. _, err = o.Raw(sql, detailPdfUrl, reportId).Exec()
  1266. return
  1267. }
  1268. func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
  1269. o := orm.NewOrmUsingDB("rddp")
  1270. sql := `UPDATE report SET detail_img_url=? WHERE id=? `
  1271. _, err = o.Raw(sql, detailImgUrl, reportId).Exec()
  1272. return
  1273. }
  1274. // UpdatePdfUrlReportById 清空pdf相关字段
  1275. func UpdatePdfUrlReportById(reportId int) (err error) {
  1276. o := orm.NewOrmUsingDB("rddp")
  1277. sql := `UPDATE report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE id = ? `
  1278. _, err = o.Raw(sql, reportId).Exec()
  1279. return
  1280. }