report.go 55 KB

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