report.go 51 KB

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