report.go 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919
  1. package models
  2. import (
  3. "errors"
  4. "eta/eta_mobile/utils"
  5. "fmt"
  6. "strings"
  7. "time"
  8. "github.com/beego/beego/v2/client/orm"
  9. "github.com/rdlucklib/rdluck_tools/paging"
  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. DetailImgUrlMobile string `description:"报告详情长图地址-手机端"`
  66. DetailPdfUrlMobile string `description:"报告详情PDF地址-手机端"`
  67. ContentStruct string `description:"内容组件"`
  68. LastModifyAdminId int `description:"最后更新人ID"`
  69. LastModifyAdminName string `description:"最后更新人姓名"`
  70. ContentModifyTime time.Time `description:"内容更新时间"`
  71. Pv int `description:"pv"`
  72. Uv int `description:"uv"`
  73. HeadImg string `description:"报告头图地址"`
  74. EndImg string `description:"报告尾图地址"`
  75. CanvasColor string `description:"画布颜色"`
  76. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  77. HeadResourceId int `description:"版头资源ID"`
  78. EndResourceId int `description:"版尾资源ID"`
  79. ClassifyIdThird int `description:"三级分类id"`
  80. ClassifyNameThird string `description:"三级分类名称"`
  81. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  82. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  83. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  84. ReportCreateTime time.Time `description:"报告时间创建时间"`
  85. InheritReportId int `description:"待继承的报告ID"`
  86. VoiceGenerateType int `description:"音频生成方式,0:系统生成,1:人工上传"`
  87. RaiReportId int `description:"RAI报告ID"`
  88. }
  89. type ReportList struct {
  90. Id int `description:"报告Id"`
  91. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  92. ClassifyIdFirst int `description:"一级分类id"`
  93. ClassifyNameFirst string `description:"一级分类名称"`
  94. ClassifyIdSecond int `description:"二级分类id"`
  95. ClassifyNameSecond string `description:"二级分类名称"`
  96. Title string `description:"标题"`
  97. Abstract string `description:"摘要"`
  98. Author string `description:"作者"`
  99. Frequency string `description:"频度"`
  100. CreateTime string `description:"创建时间"`
  101. ModifyTime time.Time `description:"修改时间"`
  102. State int `description:"1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过"`
  103. PublishTime string `description:"发布时间"`
  104. PrePublishTime string `description:"预发布时间"`
  105. Stage int `description:"期数"`
  106. MsgIsSend int `description:"模板消息是否已发送,0:否,1:是"`
  107. Content string `description:"内容"`
  108. VideoUrl string `description:"音频文件URL"`
  109. VideoName string `description:"音频文件名称"`
  110. VideoPlaySeconds string `description:"音频播放时长"`
  111. ContentSub string `description:"内容前两个章节"`
  112. Pv int `description:"Pv"`
  113. Uv int `description:"Uv"`
  114. ReportCode string `description:"报告唯一编码"`
  115. ReportVersion int `description:"1:旧版,2:新版"`
  116. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  117. NeedThsMsg int `description:"是否需要推送客群消息 0-否 1-是"`
  118. HasChapter int `description:"是否有章节 0-否 1-是"`
  119. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  120. ChapterVideoList []*ReportChapterVideoList `description:"章节音频列表"`
  121. OldReportId int `description:"research_report表ID, 大于0则表示该报告为老后台同步过来的"`
  122. MsgSendTime string `description:"模版消息发送时间"`
  123. CanEdit bool `description:"是否可编辑"`
  124. HasAuth bool `description:"是否可操作"`
  125. Editor string `description:"编辑人"`
  126. AdminId int `description:"创建者账号"`
  127. AdminRealName string `description:"创建者姓名"`
  128. ApproveTime string `description:"审批时间"`
  129. DetailImgUrl string `description:"报告详情长图地址"`
  130. DetailPdfUrl string `description:"报告详情PDF地址"`
  131. DetailImgUrlMobile string `description:"报告详情长图地址-手机端"`
  132. DetailPdfUrlMobile string `description:"报告详情PDF地址-手机端"`
  133. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  134. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  135. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  136. ReportCreateTime time.Time `description:"报告时间创建时间"`
  137. ContentStruct string `description:"内容组件"`
  138. LastModifyAdminId int `description:"最后更新人ID"`
  139. LastModifyAdminName string `description:"最后更新人姓名"`
  140. ContentModifyTime time.Time `description:"内容更新时间"`
  141. HeadImg string `description:"报告头图地址"`
  142. EndImg string `description:"报告尾图地址"`
  143. CanvasColor string `description:"画布颜色"`
  144. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  145. HeadResourceId int `description:"版头资源ID"`
  146. EndResourceId int `description:"版尾资源ID"`
  147. ClassifyIdThird int `description:"三级分类id"`
  148. ClassifyNameThird string `description:"三级分类名称"`
  149. InheritReportId int `description:"待继承的报告ID"`
  150. IsCollect int `description:"是否收藏"`
  151. ClassifyEnabled bool `description:"分类是否禁用"`
  152. RaiReportId int `description:"RAI报告ID"`
  153. }
  154. type ReportListResp struct {
  155. List []*ReportList
  156. Paging *paging.PagingItem `description:"分页数据"`
  157. }
  158. // GetReportListCountV1
  159. // @Description: 获取普通报告列表的报告数量
  160. // @author: Roc
  161. // @datetime 2024-05-30 15:14:43
  162. // @param condition string
  163. // @param pars []interface{}
  164. // @return count int
  165. // @return err error
  166. func GetReportListCountV1(condition string, pars []interface{}) (count int, err error) {
  167. o := orm.NewOrmUsingDB("rddp")
  168. sql := `SELECT COUNT(1) AS count FROM report as a WHERE 1=1 `
  169. if condition != "" {
  170. sql += condition
  171. }
  172. err = o.Raw(sql, pars).QueryRow(&count)
  173. return
  174. }
  175. // GetReportListV1
  176. // @Description: 获取普通报告列表的数据
  177. // @author: Roc
  178. // @datetime 2024-05-30 15:14:25
  179. // @param condition string
  180. // @param pars []interface{}
  181. // @param startSize int
  182. // @param pageSize int
  183. // @return items []*ReportList
  184. // @return err error
  185. func GetReportListV1(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  186. o := orm.NewOrmUsingDB("rddp")
  187. sql := `SELECT * FROM report as a WHERE 1=1 `
  188. if condition != "" {
  189. sql += condition
  190. }
  191. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  192. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  193. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  194. return
  195. }
  196. type ReportPvUv struct {
  197. ReportId int
  198. PvTotal int
  199. UvTotal int
  200. }
  201. func GetReportPvUvByReportIdList(reportIdList []int) (items []ReportPvUv, err error) {
  202. num := len(reportIdList)
  203. if num <= 0 {
  204. return
  205. }
  206. o := orm.NewOrmUsingDB("rddp")
  207. 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`
  208. _, err = o.Raw(sql, reportIdList).QueryRows(&items)
  209. return
  210. }
  211. // GetReportListCountByGrant
  212. // @Description: 获取共享报告列表的报告数量
  213. // @author: Roc
  214. // @datetime 2024-05-30 15:14:01
  215. // @param condition string
  216. // @param pars []interface{}
  217. // @return count int
  218. // @return err error
  219. func GetReportListCountByGrant(condition string, pars []interface{}) (count int, err error) {
  220. o := orm.NewOrmUsingDB("rddp")
  221. sql := `SELECT a.id FROM report as a
  222. JOIN report_grant b on a.id=b.report_id
  223. WHERE 1=1 `
  224. if condition != "" {
  225. sql += condition
  226. }
  227. sql += " GROUP BY a.id "
  228. sql = `SELECT COUNT(1) AS count FROM (` + sql + `) d`
  229. err = o.Raw(sql, pars).QueryRow(&count)
  230. return
  231. }
  232. // GetReportListByGrant
  233. // @Description: 获取共享报告列表的数据
  234. // @author: Roc
  235. // @datetime 2024-05-30 15:15:07
  236. // @param condition string
  237. // @param pars []interface{}
  238. // @param startSize int
  239. // @param pageSize int
  240. // @return items []*ReportList
  241. // @return err error
  242. func GetReportListByGrant(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  243. o := orm.NewOrmUsingDB("rddp")
  244. sql := `SELECT a.* FROM report as a JOIN report_grant b on a.id = b.report_id WHERE 1=1 `
  245. if condition != "" {
  246. sql += condition
  247. }
  248. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  249. sql += ` GROUP BY a.id ORDER BY FIELD(state,3,1,4,5,6,2), a.modify_time DESC LIMIT ?,?`
  250. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  251. return
  252. }
  253. func GetReportListCount(condition string, pars []interface{}) (count int, err error) {
  254. oRddp := orm.NewOrmUsingDB("rddp")
  255. sql := `SELECT COUNT(1) AS count FROM report WHERE 1=1 `
  256. if condition != "" {
  257. sql += condition
  258. }
  259. err = oRddp.Raw(sql, pars).QueryRow(&count)
  260. return
  261. }
  262. func GetReportList(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportList, err error) {
  263. o := orm.NewOrmUsingDB("rddp")
  264. sql := `SELECT *,
  265. (SELECT COUNT(1) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS pv,
  266. (SELECT COUNT(DISTINCT user_id) FROM report_view_record AS rvr WHERE rvr.report_id=report.id) AS uv
  267. FROM report WHERE 1=1 `
  268. if condition != "" {
  269. sql += condition
  270. }
  271. // 排序:1:未发布;2:已发布;3-待提交;4-待审批;5-已驳回;6-已通过
  272. sql += `ORDER BY FIELD(state,3,1,4,5,6,2), modify_time DESC LIMIT ?,?`
  273. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  274. return
  275. }
  276. // PublishReport 发布报告
  277. func PublishReport(reportIds []int) (err error) {
  278. if len(reportIds) == 0 {
  279. return
  280. }
  281. o := orm.NewOrmUsingDB("rddp")
  282. sql := `UPDATE report SET state=2,publish_time=now(),modify_time=NOW() WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  283. _, err = o.Raw(sql).Exec()
  284. return
  285. }
  286. // PublishCancelReport 取消发布报告
  287. func PublishCancelReport(reportId, state int, publishTimeNullFlag bool, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  288. o := orm.NewOrmUsingDB("rddp")
  289. var sql string
  290. if publishTimeNullFlag {
  291. sql = ` UPDATE report SET state=?, publish_time=null, pre_publish_time=null, pre_msg_send=0,last_modify_admin_id=?,last_modify_admin_name=?,modify_time = NOW() WHERE id =?`
  292. } else {
  293. sql = ` UPDATE report SET state=?, pre_publish_time=null, pre_msg_send=0,last_modify_admin_id=?,last_modify_admin_name=?,modify_time = NOW() WHERE id =?`
  294. }
  295. _, err = o.Raw(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Exec()
  296. return
  297. }
  298. // 删除报告
  299. func DeleteReport(reportIds int) (err error) {
  300. o := orm.NewOrmUsingDB("rddp")
  301. sql := ` DELETE FROM report WHERE id =? `
  302. _, err = o.Raw(sql, reportIds).Exec()
  303. return
  304. }
  305. type ReportDetail struct {
  306. Id int `orm:"column(id)" description:"报告Id"`
  307. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  308. ClassifyIdFirst int `description:"一级分类id"`
  309. ClassifyNameFirst string `description:"一级分类名称"`
  310. ClassifyIdSecond int `description:"二级分类id"`
  311. ClassifyNameSecond string `description:"二级分类名称"`
  312. Title string `description:"标题"`
  313. Abstract string `description:"摘要"`
  314. Author string `description:"作者"`
  315. Frequency string `description:"频度"`
  316. CreateTime string `description:"创建时间"`
  317. ModifyTime string `description:"修改时间"`
  318. State int `description:"1:未发布,2:已发布"`
  319. PublishTime string `description:"发布时间"`
  320. PrePublishTime string `description:"预发布时间"`
  321. Stage int `description:"期数"`
  322. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  323. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  324. Content string `description:"内容"`
  325. VideoUrl string `description:"音频文件URL"`
  326. VideoName string `description:"音频文件名称"`
  327. VideoPlaySeconds string `description:"音频播放时长"`
  328. ContentSub string `description:"内容前两个章节"`
  329. ThsMsgIsSend int `description:"客户群消息是否已发送,0:否,1:是"`
  330. HasChapter int `description:"是否有章节 0-否 1-是"`
  331. ChapterType string `description:"章节类型 day-晨报 week-周报"`
  332. AdminId int `description:"创建者账号"`
  333. AdminRealName string `description:"创建者姓名"`
  334. ReportCode string `description:"报告唯一编码"`
  335. // eta1.8.3(研报改版)相关内容
  336. ContentStruct string `description:"内容组件"`
  337. LastModifyAdminId int `description:"最后更新人ID"`
  338. LastModifyAdminName string `description:"最后更新人姓名"`
  339. ContentModifyTime time.Time `description:"内容更新时间"`
  340. Pv int `description:"pv"`
  341. Uv int `description:"uv"`
  342. HeadImg string `description:"报告头图地址"`
  343. EndImg string `description:"报告尾图地址"`
  344. HeadStyle string `description:"版头样式"`
  345. EndStyle string `description:"版尾样式"`
  346. CanvasColor string `description:"画布颜色"`
  347. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  348. HeadResourceId int `description:"版头资源ID"`
  349. EndResourceId int `description:"版尾资源ID"`
  350. ClassifyIdThird int `description:"三级分类id"`
  351. ClassifyNameThird string `description:"三级分类名称"`
  352. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  353. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  354. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  355. ReportCreateTime time.Time `description:"报告时间创建时间"`
  356. ClassifyEnabled bool `description:"分类是否禁用"`
  357. RaiReportId int `description:"RAI报告ID"`
  358. }
  359. func GetReportById(reportId int) (item *ReportDetail, err error) {
  360. o := orm.NewOrmUsingDB("rddp")
  361. sql := `SELECT * FROM report WHERE id=?`
  362. err = o.Raw(sql, reportId).QueryRow(&item)
  363. return
  364. }
  365. func GetReportByIds(reportIds string) (list []*ReportDetail, err error) {
  366. o := orm.NewOrmUsingDB("rddp")
  367. sql := `SELECT * FROM report WHERE id in ` + reportIds
  368. _, err = o.Raw(sql).QueryRows(&list)
  369. return
  370. }
  371. // GetSimpleReportByIds 根据报告ID查询报告基本信息
  372. func GetSimpleReportByIds(reportIds []int) (list []*Report, err error) {
  373. if len(reportIds) == 0 {
  374. return
  375. }
  376. o := orm.NewOrmUsingDB("rddp")
  377. sql := `SELECT id, title, report_code FROM report WHERE id IN (` + utils.GetOrmInReplace(len(reportIds)) + `)`
  378. _, err = o.Raw(sql, reportIds).QueryRows(&list)
  379. return
  380. }
  381. // GetReportStage
  382. // @Description: 获取报告的最大期数(每一年的最大期数)
  383. // @author: Roc
  384. // @datetime 2024-06-03 17:44:14
  385. // @param classifyIdFirst int
  386. // @param classifyIdSecond int
  387. // @param classifyIdThird int
  388. // @return count int
  389. // @return err error
  390. func GetReportStage(classifyIdFirst, classifyIdSecond, classifyIdThird int) (count int, err error) {
  391. o := orm.NewOrmUsingDB("rddp")
  392. classifyId := classifyIdThird
  393. if classifyId <= 0 {
  394. classifyId = classifyIdSecond
  395. }
  396. if classifyId <= 0 {
  397. classifyId = classifyIdFirst
  398. }
  399. if classifyId <= 0 {
  400. err = errors.New("错误的分类id")
  401. return
  402. }
  403. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  404. sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? `
  405. if classifyIdThird > 0 {
  406. sql += " AND classify_id_third = ? "
  407. } else if classifyIdSecond > 0 {
  408. sql += " AND classify_id_second = ? "
  409. } else {
  410. sql += " AND classify_id_first = ? "
  411. }
  412. o.Raw(sql, yearStart, classifyId).QueryRow(&count)
  413. return
  414. }
  415. // GetReportStageEdit
  416. // @Description: 获取报告的最大期数(每一年的最大期数)
  417. // @author: Roc
  418. // @datetime 2024-06-04 13:50:34
  419. // @param classifyIdFirst int
  420. // @param classifyIdSecond int
  421. // @param classifyIdThird int
  422. // @param reportId int
  423. // @return count int
  424. // @return err error
  425. func GetReportStageEdit(classifyIdFirst, classifyIdSecond, classifyIdThird, reportId int) (count int, err error) {
  426. classifyId := classifyIdThird
  427. if classifyId <= 0 {
  428. classifyId = classifyIdSecond
  429. }
  430. if classifyId <= 0 {
  431. classifyId = classifyIdFirst
  432. }
  433. if classifyId <= 0 {
  434. err = errors.New("错误的分类id")
  435. return
  436. }
  437. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  438. sql := `SELECT MAX(stage) AS max_stage FROM report WHERE create_time > ? AND id<>? `
  439. if classifyIdThird > 0 {
  440. sql += " AND classify_id_third = ? "
  441. } else if classifyIdSecond > 0 {
  442. sql += " AND classify_id_second = ? "
  443. } else {
  444. sql = " AND classify_id_first = ? "
  445. }
  446. o := orm.NewOrmUsingDB("rddp")
  447. o.Raw(sql, yearStart, reportId, classifyId).QueryRow(&count)
  448. return
  449. }
  450. type PublishReq struct {
  451. ReportIds string `description:"报告id,多个用英文逗号隔开"`
  452. ReportUrl string `description:"报告Url"`
  453. }
  454. type PublishCancelReq struct {
  455. ReportIds int `description:"报告id"`
  456. }
  457. type DeleteReq struct {
  458. ReportIds int `description:"报告id"`
  459. }
  460. type AddReq struct {
  461. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  462. ClassifyIdFirst int `description:"一级分类id"`
  463. ClassifyNameFirst string `description:"一级分类名称"`
  464. ClassifyIdSecond int `description:"二级分类id"`
  465. ClassifyNameSecond string `description:"二级分类名称"`
  466. ClassifyIdThird int `description:"三级分类id"`
  467. ClassifyNameThird string `description:"三级分类名称"`
  468. Title string `description:"标题"`
  469. Abstract string `description:"摘要"`
  470. Author string `description:"作者"`
  471. Frequency string `description:"频度"`
  472. State int `description:"状态:1:未发布,2:已发布"`
  473. Content string `description:"内容"`
  474. CreateTime string `description:"创建时间"`
  475. ReportVersion int `description:"1:旧版,2:新版"`
  476. ContentStruct string `description:"内容组件"`
  477. HeadImg string `description:"报告头图地址"`
  478. EndImg string `description:"报告尾图地址"`
  479. CanvasColor string `description:"画布颜色"`
  480. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  481. HeadResourceId int `description:"版头资源ID"`
  482. EndResourceId int `description:"版尾资源ID"`
  483. CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  484. ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  485. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  486. InheritReportId int `description:"待继承的报告ID"`
  487. GrantAdminIdList []int `description:"授权用户id列表"`
  488. }
  489. type PrePublishReq struct {
  490. ReportId int `description:"报告id"`
  491. PrePublishTime string `description:"预发布时间"`
  492. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  493. ReportUrl string `description:"报告Url"`
  494. }
  495. type AddResp struct {
  496. ReportId int64 `description:"报告id"`
  497. ReportCode string `description:"报告code"`
  498. }
  499. func AddReport(item *Report) (lastId int64, err error) {
  500. o := orm.NewOrmUsingDB("rddp")
  501. lastId, err = o.Insert(item)
  502. return
  503. }
  504. type EditReq struct {
  505. ReportId int64 `description:"报告id"`
  506. ClassifyIdFirst int `description:"一级分类id"`
  507. ClassifyNameFirst string `description:"一级分类名称"`
  508. ClassifyIdSecond int `description:"二级分类id"`
  509. ClassifyNameSecond string `description:"二级分类名称"`
  510. ClassifyIdThird int `description:"三级分类id"`
  511. ClassifyNameThird string `description:"三级分类名称"`
  512. Title string `description:"标题"`
  513. Abstract string `description:"摘要"`
  514. Author string `description:"作者"`
  515. Frequency string `description:"频度"`
  516. State int `description:"状态:1:未发布,2:已发布"`
  517. Content string `description:"内容"`
  518. CreateTime string `description:"创建时间"`
  519. ContentStruct string `description:"内容组件"`
  520. HeadImg string `description:"报告头图地址"`
  521. EndImg string `description:"报告尾图地址"`
  522. CanvasColor string `description:"画布颜色"`
  523. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  524. HeadResourceId int `description:"版头资源ID"`
  525. EndResourceId int `description:"版尾资源ID"`
  526. //CollaborateType int8 `description:"协作方式,1:个人,2:多人协作。默认:1"`
  527. //ReportLayout int8 `description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  528. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  529. GrantAdminIdList []int `description:"授权用户id列表"`
  530. }
  531. type EditResp struct {
  532. ReportId int64 `description:"报告id"`
  533. ReportCode string `description:"报告code"`
  534. }
  535. func EditReport(item *Report, reportId int64) (err error) {
  536. o := orm.NewOrmUsingDB("rddp")
  537. sql := `UPDATE report
  538. SET
  539. classify_id_first =?,
  540. classify_name_first = ?,
  541. classify_id_second = ?,
  542. classify_name_second = ?,
  543. title = ?,
  544. abstract = ?,
  545. author = ?,
  546. frequency = ?,
  547. state = ?,
  548. content = ?,
  549. content_sub = ?,
  550. stage =?,
  551. create_time = ?,
  552. modify_time = ?
  553. WHERE id = ? `
  554. _, err = o.Raw(sql, item.ClassifyIdFirst, item.ClassifyNameFirst, item.ClassifyIdSecond, item.ClassifyNameSecond, item.Title,
  555. item.Abstract, item.Author, item.Frequency, item.State, item.Content, item.ContentSub, item.Stage, item.CreateTime, time.Now(), reportId).Exec()
  556. return
  557. }
  558. func (m *Report) Update(cols []string) (err error) {
  559. o := orm.NewOrmUsingDB("rddp")
  560. _, err = o.Update(m, cols...)
  561. return
  562. }
  563. type ReportDetailReq struct {
  564. ReportId int `description:"报告id"`
  565. }
  566. type ClassifyIdDetailReq struct {
  567. ClassifyIdFirst int `description:"报告一级分类id"`
  568. ClassifyIdSecond int `description:"报告二级分类id"`
  569. }
  570. func GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond int) (item *Report, err error) {
  571. o := orm.NewOrmUsingDB("rddp")
  572. sql := ` SELECT * FROM report WHERE 1=1 `
  573. if classifyIdSecond > 0 {
  574. sql = sql + ` AND classify_id_second=? ORDER BY stage DESC LIMIT 1`
  575. err = o.Raw(sql, classifyIdSecond).QueryRow(&item)
  576. } else {
  577. sql = sql + ` AND classify_id_first=? ORDER BY stage DESC LIMIT 1`
  578. err = o.Raw(sql, classifyIdFirst).QueryRow(&item)
  579. }
  580. return
  581. }
  582. type SendTemplateMsgReq struct {
  583. ReportId int `description:"报告id"`
  584. }
  585. // SendTemplateMsgResp
  586. // @Description: 报告推送返回结构体
  587. type SendTemplateMsgResp struct {
  588. ReportId int `description:"报告id"`
  589. MsgSendTime string `description:"报告推送时间"`
  590. }
  591. func ModifyReportMsgIsSend(reportId int) (err error) {
  592. o := orm.NewOrmUsingDB("rddp")
  593. report, err := GetReportById(reportId)
  594. if err != nil {
  595. return
  596. }
  597. if report.MsgIsSend == 0 {
  598. sql := `UPDATE report SET msg_is_send = 1, msg_send_time=NOW() WHERE id = ? `
  599. _, err = o.Raw(sql, reportId).Exec()
  600. }
  601. return
  602. }
  603. func ModifyReportVideo(reportId int, videoUrl, videoName, videoSize string, playSeconds float64) (err error) {
  604. o := orm.NewOrmUsingDB("rddp")
  605. sql := `UPDATE report SET video_url=?,video_name=?,video_play_seconds=?,video_size=? WHERE id=? `
  606. _, err = o.Raw(sql, videoUrl, videoName, playSeconds, videoSize, reportId).Exec()
  607. return
  608. }
  609. type ReportItem struct {
  610. Id int `orm:"column(id)" description:"报告Id"`
  611. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  612. ClassifyIdFirst int `description:"一级分类id"`
  613. ClassifyNameFirst string `description:"一级分类名称"`
  614. ClassifyIdSecond int `description:"二级分类id"`
  615. ClassifyNameSecond string `description:"二级分类名称"`
  616. Title string `description:"标题"`
  617. Abstract string `description:"摘要"`
  618. Author string `description:"作者"`
  619. Frequency string `description:"频度"`
  620. CreateTime time.Time `description:"创建时间"`
  621. ModifyTime time.Time `description:"修改时间"`
  622. State int `description:"1:未发布,2:已发布"`
  623. PublishTime time.Time `description:"发布时间"`
  624. Stage int `description:"期数"`
  625. MsgIsSend int `description:"消息是否已发送,0:否,1:是"`
  626. Content string `description:"内容"`
  627. VideoUrl string `description:"音频文件URL"`
  628. VideoName string `description:"音频文件名称"`
  629. VideoPlaySeconds string `description:"音频播放时长"`
  630. ContentSub string `description:"内容前两个章节"`
  631. }
  632. func GetReportItemById(reportId int) (item *ReportItem, err error) {
  633. o := orm.NewOrmUsingDB("rddp")
  634. sql := `SELECT * FROM report WHERE id=?`
  635. err = o.Raw(sql, reportId).QueryRow(&item)
  636. return
  637. }
  638. type SaveReportContent struct {
  639. Content string `description:"内容"`
  640. ReportId int `description:"报告id"`
  641. NoChange int `description:"内容是否未改变:1:内容未改变"`
  642. // 以下是智能研报相关
  643. ContentStruct string `description:"内容组件"`
  644. HeadImg string `description:"报告头图地址"`
  645. EndImg string `description:"报告尾图地址"`
  646. CanvasColor string `description:"画布颜色"`
  647. NeedSplice int `description:"是否拼接版头版位的标记,主要是为了兼容历史报告。0-不需要 1-需要"`
  648. HeadResourceId int `description:"版头资源ID"`
  649. EndResourceId int `description:"版尾资源ID"`
  650. }
  651. func EditReportContent(reportId int, content, contentSub string) (err error) {
  652. o := orm.NewOrmUsingDB("rddp")
  653. sql := ` UPDATE report SET content=?,content_sub=?,modify_time=NOW() WHERE id=? `
  654. _, err = o.Raw(sql, content, contentSub, reportId).Exec()
  655. return
  656. }
  657. func AddReportSaveLog(reportId, adminId int, content, contentSub, contentStruct, canvasColor, adminName string, headResourceId, endResourceId int) (err error) {
  658. o := orm.NewOrmUsingDB("rddp")
  659. 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 (?,?,?,?,?,?,?,?,?) `
  660. _, err = o.Raw(sql, reportId, content, contentSub, contentStruct, canvasColor, headResourceId, endResourceId, adminId, adminName).Exec()
  661. return
  662. }
  663. func MultiAddReportChaptersSaveLog(items []*ReportChapter, adminId int, adminRealName string) (err error) {
  664. o := orm.NewOrmUsingDB("rddp")
  665. p, err := o.Raw(`INSERT INTO report_save_log(report_id, report_chapter_id, content, content_sub,content_struct,admin_id, admin_name) VALUES (?,?,?,?,?,?,?)`).Prepare()
  666. if err != nil {
  667. return
  668. }
  669. defer func() {
  670. _ = p.Close()
  671. }()
  672. for _, v := range items {
  673. _, err = p.Exec(v.ReportId, v.ReportChapterId, v.Content, v.ContentSub, v.ContentStruct, adminId, adminRealName)
  674. if err != nil {
  675. return
  676. }
  677. }
  678. return
  679. }
  680. type SaveReportContentResp struct {
  681. ReportId int `description:"报告id"`
  682. }
  683. func ModifyReportCode(reportId int64, reportCode string) (err error) {
  684. o := orm.NewOrmUsingDB("rddp")
  685. sql := `UPDATE report SET report_code=? WHERE id=? `
  686. _, err = o.Raw(sql, reportCode, reportId).Exec()
  687. return
  688. }
  689. func ModifyReportThsMsgIsSend(item *ReportDetail) (err error) {
  690. o := orm.NewOrmUsingDB("rddp")
  691. if item.ThsMsgIsSend == 0 {
  692. sql := `UPDATE report SET ths_msg_is_send = 1 WHERE id = ? `
  693. _, err = o.Raw(sql, item.Id).Exec()
  694. }
  695. return
  696. }
  697. type ThsSendTemplateMsgReq struct {
  698. ReportId []int `description:"报告id"`
  699. }
  700. type PublishDayWeekReportReq struct {
  701. ReportId int `description:"报告ID"`
  702. }
  703. // SaveDayWeekReportReq 新增晨报周报请求体
  704. type SaveDayWeekReportReq struct {
  705. ReportId int `description:"报告ID"`
  706. Title string `description:"标题"`
  707. ReportType string `description:"一级分类ID"`
  708. Author string `description:"作者"`
  709. CreateTime string `description:"创建时间"`
  710. }
  711. // GetDayWeekReportStage 获取晨报周报期数
  712. func GetDayWeekReportStage(classifyIdFirst int, yearStart time.Time) (count int, err error) {
  713. o := orm.NewOrmUsingDB("rddp")
  714. sql := " SELECT MAX(stage) AS max_stage FROM report WHERE classify_id_first = ? AND create_time > ? "
  715. o.Raw(sql, classifyIdFirst, yearStart).QueryRow(&count)
  716. return
  717. }
  718. // GetReportByReportId 主键获取报告
  719. func GetReportByReportId(reportId int) (item *Report, err error) {
  720. o := orm.NewOrmUsingDB("rddp")
  721. sql := `SELECT * FROM report WHERE id = ?`
  722. err = o.Raw(sql, reportId).QueryRow(&item)
  723. return
  724. }
  725. // GetReportByOldReportId 根据老报告id主键获取报告
  726. func GetReportByOldReportId(reportId int) (item *Report, err error) {
  727. o := orm.NewOrmUsingDB("rddp")
  728. sql := `SELECT * FROM report WHERE old_report_id = ?`
  729. err = o.Raw(sql, reportId).QueryRow(&item)
  730. return
  731. }
  732. // DeleteDayWeekReportAndChapter 删除晨周报及章节
  733. func DeleteDayWeekReportAndChapter(reportId int) (err error) {
  734. o := orm.NewOrmUsingDB("rddp")
  735. to, err := o.Begin()
  736. if err != nil {
  737. return
  738. }
  739. defer func() {
  740. if err != nil {
  741. _ = to.Rollback()
  742. } else {
  743. _ = to.Commit()
  744. }
  745. }()
  746. sql := ` DELETE FROM report WHERE id = ? LIMIT 1 `
  747. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  748. return
  749. }
  750. sql = ` DELETE FROM report_chapter WHERE report_id = ? `
  751. if _, err = to.Raw(sql, reportId).Exec(); err != nil {
  752. return
  753. }
  754. return
  755. }
  756. // UpdateReport 更新报告
  757. func (reportInfo *Report) UpdateReport(cols []string) (err error) {
  758. o := orm.NewOrmUsingDB("rddp")
  759. _, err = o.Update(reportInfo, cols...)
  760. return
  761. }
  762. // ReportDetailView
  763. // @Description: 晨周报详情
  764. type ReportDetailView struct {
  765. *ReportDetail
  766. ChapterList []*ReportChapter
  767. GrandAdminList []ReportDetailViewAdmin
  768. PermissionList []ReportDetailViewPermission
  769. }
  770. // ReportDetailViewAdmin
  771. // @Description: 报告里面的授权人
  772. type ReportDetailViewAdmin struct {
  773. AdminId int
  774. AdminName string
  775. }
  776. // ReportDetailViewPermission
  777. // @Description: 报告分类关联的品种权限
  778. type ReportDetailViewPermission struct {
  779. PermissionId int
  780. PermissionName string
  781. }
  782. func GetUnPublishDayReport(startTime time.Time, endTime time.Time) (item *Report, err error) {
  783. o := orm.NewOrmUsingDB("rddp")
  784. sql := ` SELECT
  785. *
  786. FROM
  787. report AS a
  788. WHERE
  789. a.has_chapter = 1
  790. AND a.chapter_type = "day"
  791. AND a.state = 1
  792. AND (
  793. a.create_time BETWEEN ? AND ?
  794. )
  795. ORDER BY
  796. a.create_time DESC
  797. LIMIT 1 `
  798. err = o.Raw(sql, startTime, endTime).QueryRow(&item)
  799. return
  800. }
  801. type ElasticReportDetail struct {
  802. ReportId int `description:"报告ID"`
  803. ReportChapterId int `description:"报告章节ID"`
  804. Title string `description:"标题"`
  805. Abstract string `description:"摘要"`
  806. BodyContent string `description:"内容"`
  807. PublishTime string `description:"发布时间"`
  808. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  809. IsPublicPublish int8 `description:"是否公开发布,1:是,2:否"`
  810. Author string `description:"作者"`
  811. ClassifyIdFirst int `description:"一级分类ID"`
  812. ClassifyNameFirst string `description:"一级分类名称"`
  813. ClassifyIdSecond int `description:"二级分类ID"`
  814. ClassifyNameSecond string `description:"二级分类名称"`
  815. ClassifyId int `description:"最小单元的分类ID"`
  816. ClassifyName 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, 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. _, err = to.Update(reportInfo, cols...)
  851. if err != nil {
  852. return
  853. }
  854. }
  855. // 发布该报告的所有章节
  856. sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? `
  857. _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id).Exec()
  858. // 发布章节
  859. //if len(publishIds) > 0 {
  860. // sql := ` UPDATE report_chapter SET publish_state = 2, publish_time = ? WHERE report_id = ? AND report_chapter_id IN (` + utils.GetOrmInReplace(len(publishIds)) + `) `
  861. // _, err = to.Raw(sql, reportInfo.PublishTime, reportInfo.Id, publishIds).Exec()
  862. //}
  863. //if len(unPublishIds) > 0 {
  864. // 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)) + `) `
  865. // _, err = to.Raw(sql, reportInfo.Id, unPublishIds).Exec()
  866. //}
  867. return
  868. }
  869. func GetSyncEmptyVideoReport() (list []*Report, err error) {
  870. o := orm.NewOrmUsingDB("rddp")
  871. sql := ` SELECT id FROM report WHERE old_report_id > 0 AND state = 2 AND chapter_type = "" AND (video_size = "" OR video_play_seconds = "")
  872. UNION ALL
  873. SELECT DISTINCT report_id FROM report_chapter WHERE publish_state = 2 AND (video_size = "" OR video_play_seconds = "") `
  874. _, err = o.Raw(sql).QueryRows(&list)
  875. return
  876. }
  877. // PublishReportById 发布报告
  878. func PublishReportById(reportId int, publishTime time.Time, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  879. o := orm.NewOrmUsingDB("rddp")
  880. sql := `UPDATE report SET state = 2, publish_time = ?, pre_publish_time=null, pre_msg_send=0, modify_time = NOW(),last_modify_admin_id=?,last_modify_admin_name=? WHERE id = ? `
  881. _, err = o.Raw(sql, publishTime, lastModifyAdminId, lastModifyAdminName, reportId).Exec()
  882. return
  883. }
  884. // ResetReportById 重置报告状态
  885. func ResetReportById(reportId, state int, lastModifyAdminId int, lastModifyAdminName string) (err error) {
  886. o := orm.NewOrmUsingDB("rddp")
  887. sql := `UPDATE report SET state = ?, pre_publish_time = null, pre_msg_send = 0, modify_time = NOW(),last_modify_admin_id=?,last_modify_admin_name=? WHERE id = ?`
  888. _, err = o.Raw(sql, state, lastModifyAdminId, lastModifyAdminName, reportId).Exec()
  889. return
  890. }
  891. // GetCommentReportByReportId 查询有留言的报告列表
  892. func GetCommentReportByReportId(condition string, pars []interface{}, startSize, pageSize int) (list []*Report, err error) {
  893. o := orm.NewOrmUsingDB("rddp")
  894. sql := `SELECT
  895. id,
  896. create_time,
  897. title,
  898. classify_name_first,
  899. classify_id_first,
  900. classify_name_second,
  901. classify_id_second,
  902. state,
  903. IF
  904. ( publish_time, publish_time, create_time ) AS publish_time
  905. FROM
  906. report
  907. WHERE
  908. 1=1
  909. `
  910. if condition != "" {
  911. sql += condition
  912. }
  913. sql += ` ORDER BY publish_time DESC , title ASC LIMIT ?,?`
  914. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  915. return
  916. }
  917. // GetCommentReportByReportIdOrderBy 查询有留言的报告列表(指定排序)
  918. func GetCommentReportByReportIdOrderBy(condition string, pars []interface{}, startSize, pageSize int, orderBy string) (list []*Report, err error) {
  919. o := orm.NewOrmUsingDB("rddp")
  920. sql := `SELECT
  921. id,
  922. create_time,
  923. title,
  924. classify_name_first,
  925. classify_id_first,
  926. classify_name_second,
  927. classify_id_second,
  928. state,
  929. IF
  930. ( publish_time, publish_time, create_time ) AS publish_time
  931. FROM
  932. report
  933. WHERE
  934. 1=1
  935. `
  936. if condition != "" {
  937. sql += condition
  938. }
  939. if orderBy == `` {
  940. sql += ` ORDER BY publish_time DESC , title ASC `
  941. } else {
  942. sql += orderBy
  943. }
  944. sql += ` LIMIT ?,? `
  945. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  946. return
  947. }
  948. // GetCommentReportTotalByReportId 查询有留言的报告列表总数
  949. func GetCommentReportTotalByReportId(condition string, pars []interface{}) (total int64, err error) {
  950. o := orm.NewOrmUsingDB("rddp")
  951. sql := `SELECT count(*)
  952. FROM report WHERE 1=1`
  953. if condition != "" {
  954. sql += condition
  955. }
  956. err = o.Raw(sql, pars).QueryRow(&total)
  957. return
  958. }
  959. // 点赞相关的报告列表
  960. type LikeReportItem struct {
  961. ReportId int `description:"报告Id"`
  962. ReportChapterId int `description:"报告章节Id"`
  963. ClassifyIdFirst int `description:"一级分类id"`
  964. ClassifyNameFirst string `description:"一级分类名称"`
  965. ClassifyIdSecond int `description:"二级分类id"`
  966. ClassifyNameSecond string `description:"二级分类名称"`
  967. ReportChapterTypeId int `description:"章节类型"`
  968. ReportChapterTypeName string `description:"品种名称"`
  969. PublishTime time.Time `description:"发布时间" `
  970. Title string `description:"标题"`
  971. }
  972. // GetLikeReportByReportIdReportChapterId 获取有被点赞的报告列表
  973. func GetLikeReportByReportIdReportChapterId(reportIds string, chapterIds string, orderStr string, startSize, pageSize int) (list []*LikeReportItem, err error) {
  974. o := orm.NewOrmUsingDB("rddp")
  975. sql := `( SELECT
  976. id AS report_id,
  977. 0 AS report_chapter_id,
  978. classify_id_first,
  979. classify_id_second,
  980. classify_name_first,
  981. classify_name_second,
  982. 0 as report_chapter_type_id,
  983. "" as report_chapter_type_name,
  984. publish_time,
  985. title
  986. FROM
  987. report
  988. WHERE
  989. classify_name_first != "晨报"
  990. AND classify_name_first != "周报"
  991. AND id in (` + reportIds + `)
  992. )
  993. UNION
  994. ( SELECT
  995. report_id,
  996. report_chapter_id,
  997. classify_id_first,
  998. 0 as classify_id_second,
  999. classify_name_first,
  1000. null as classify_name_second,
  1001. type_id as report_chapter_type_id,
  1002. type_name as report_chapter_type_name,
  1003. publish_time,
  1004. title
  1005. FROM
  1006. report_chapter
  1007. WHERE
  1008. report_chapter_id in (` + chapterIds + `)
  1009. )`
  1010. if orderStr != "" {
  1011. sql += ` ORDER BY FIELD(CONCAT(report_id, "-",report_chapter_id),` + orderStr + `)`
  1012. } else {
  1013. sql += ` ORDER BY publish_time DESC, report_id Desc`
  1014. }
  1015. sql += ` LIMIT ?,?`
  1016. _, err = o.Raw(sql, startSize, pageSize).QueryRows(&list)
  1017. return
  1018. }
  1019. // GetLikeReportTotalByReportIdReportChapterId 获取有被点赞的报告列表总数
  1020. func GetLikeReportTotalByReportIdReportChapterId(reportIds string, chapterIds string) (total int64, err error) {
  1021. o := orm.NewOrmUsingDB("rddp")
  1022. sql := `select count(*) from (( SELECT
  1023. id AS report_id,
  1024. 0 AS report_chapter_id,
  1025. classify_id_first,
  1026. classify_id_second,
  1027. classify_name_first,
  1028. classify_name_second,
  1029. 0 as report_chapter_type_id,
  1030. publish_time,
  1031. title
  1032. FROM
  1033. report
  1034. WHERE
  1035. classify_name_first != "晨报"
  1036. AND classify_name_first != "周报"
  1037. AND id in (` + reportIds + `)
  1038. )
  1039. UNION
  1040. ( SELECT
  1041. report_id,
  1042. report_chapter_id,
  1043. classify_id_first,
  1044. 0 as classify_id_second,
  1045. classify_name_first,
  1046. null as classify_name_second,
  1047. type_id as report_chapter_type_id,
  1048. publish_time,
  1049. title
  1050. FROM
  1051. report_chapter
  1052. WHERE
  1053. report_chapter_id in (` + chapterIds + `)
  1054. )) r`
  1055. err = o.Raw(sql).QueryRow(&total)
  1056. return
  1057. }
  1058. // GetPageReportList 分页获取报告列表
  1059. func GetPageReportList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*ReportList, err error) {
  1060. o := orm.NewOrmUsingDB("rddp")
  1061. sql := `SELECT * FROM report WHERE 1=1 `
  1062. sql += condition
  1063. sql += ` ORDER BY modify_time DESC`
  1064. totalSql := `SELECT COUNT(1) total FROM (` + sql + `) z `
  1065. err = o.Raw(totalSql, pars).QueryRow(&total)
  1066. if err != nil {
  1067. return
  1068. }
  1069. sql += ` LIMIT ?,? `
  1070. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1071. return
  1072. }
  1073. // SunCodeReq 获取太阳码请求体
  1074. type SunCodeReq struct {
  1075. CodePage string `json:"CodePage" description:"太阳码page"`
  1076. CodeScene string `json:"CodeScene" description:"太阳码scene"`
  1077. }
  1078. // YbPcSuncode 活动海报表
  1079. type YbPcSuncode struct {
  1080. SuncodeID uint32 `orm:"column(suncode_id);pk" `
  1081. Scene string `gorm:"column:scene;type:varchar(255);not null;default:0" json:"scene"` // 微信scene
  1082. SceneMd5 string `gorm:"column:scene_md5;type:varchar(255);not null" json:"sceneMd5"`
  1083. CodePage string `gorm:"column:code_page;type:varchar(255);not null;default:''" json:"codePage"` // 路径
  1084. SuncodeUrl string `gorm:"column:suncode_url;type:varchar(255);not null;default:''" json:"suncodeUrl"` // 太阳码储存地址
  1085. CreateTime time.Time `gorm:"column:create_time;type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"`
  1086. }
  1087. // GetYbPcSunCode 获取太阳码
  1088. func GetYbPcSunCode(scene, page string) (item *YbPcSuncode, err error) {
  1089. o := orm.NewOrmUsingDB("weekly")
  1090. sql := `SELECT * FROM yb_pc_suncode WHERE scene = ? AND code_page = ? `
  1091. err = o.Raw(sql, scene, page).QueryRow(&item)
  1092. return
  1093. }
  1094. func AddYbPcSunCode(item *YbPcSuncode) (err error) {
  1095. o := orm.NewOrmUsingDB("weekly")
  1096. _, err = o.Insert(item)
  1097. return
  1098. }
  1099. // YbSuncodePars 小程序太阳码scene参数
  1100. type YbSuncodePars struct {
  1101. ID uint32 `orm:"column(id);pk" `
  1102. Scene string `gorm:"column:scene;type:varchar(255);not null;default:''" json:"scene"` // scene参数
  1103. SceneKey string `gorm:"column:scene_key;type:varchar(32);not null;default:''" json:"scene_key"` // MD5值
  1104. CreateTime time.Time `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createTime"`
  1105. }
  1106. func AddYbSuncodePars(item *YbSuncodePars) (err error) {
  1107. o := orm.NewOrmUsingDB("weekly")
  1108. _, err = o.Insert(item)
  1109. return
  1110. }
  1111. // UpdateReportSecondClassifyNameByClassifyId 更新报告分类名称字段
  1112. func UpdateReportSecondClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1113. o := orm.NewOrmUsingDB("rddp")
  1114. sql := " UPDATE report SET classify_name_second = ? WHERE classify_id_second = ? "
  1115. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1116. return
  1117. }
  1118. // UpdateReportFirstClassifyNameByClassifyId 更新报告分类一级名称字段
  1119. func UpdateReportFirstClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1120. o := orm.NewOrmUsingDB("rddp")
  1121. sql := " UPDATE report SET classify_name_first = ? WHERE classify_id_first = ? "
  1122. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1123. return
  1124. }
  1125. // UpdateReportThirdClassifyNameByClassifyId 更新报告的三级分类名称字段
  1126. func UpdateReportThirdClassifyNameByClassifyId(classifyId int, classifyName string) (err error) {
  1127. o := orm.NewOrmUsingDB("rddp")
  1128. sql := " UPDATE report SET classify_name_third = ? WHERE classify_id_third = ? "
  1129. _, err = o.Raw(sql, classifyName, classifyId).Exec()
  1130. return
  1131. }
  1132. // UpdateReportSecondClassifyFirstNameByClassifyId 更新报告二级分类的一级分类名称和id
  1133. func UpdateReportSecondClassifyFirstNameByClassifyId(classifyId, newClassifyId int, classifyName string) (err error) {
  1134. o := orm.NewOrmUsingDB("rddp")
  1135. sql := " UPDATE report SET classify_name_first = ?, classify_id_first = ? WHERE classify_id_second = ? "
  1136. _, err = o.Raw(sql, classifyName, newClassifyId, classifyId).Exec()
  1137. return
  1138. }
  1139. // GetEmptyContentSubPPTReport 获取前两章为空的PPT报告
  1140. func GetEmptyContentSubPPTReport() (list []*Report, err error) {
  1141. sql := `SELECT
  1142. r.id,
  1143. r.content,
  1144. r.content_sub
  1145. FROM
  1146. report AS r
  1147. JOIN ppt_v2 AS p ON r.id = p.report_id
  1148. WHERE
  1149. p.report_id > 0 AND r.content_sub = ""`
  1150. _, err = orm.NewOrmUsingDB("rddp").Raw(sql).QueryRows(&list)
  1151. return
  1152. }
  1153. // ModifyReportAuthor 更改报告作者
  1154. func ModifyReportAuthor(condition string, pars []interface{}, authorName string) (count int, err error) {
  1155. //产品权限
  1156. oRddp := orm.NewOrmUsingDB("rddp")
  1157. sql := `UPDATE english_report set author = ? WHERE 1=1 `
  1158. if condition != "" {
  1159. sql += condition
  1160. }
  1161. err = oRddp.Raw(sql, authorName, pars).QueryRow(&count)
  1162. return
  1163. }
  1164. func UpdateReportPublishTime(reportId int, videoNameDate string) (err error) {
  1165. o := orm.NewOrmUsingDB("rddp")
  1166. sql1 := ` UPDATE report SET publish_time = NOW() WHERE id = ? `
  1167. _, err = o.Raw(sql1, reportId).Exec()
  1168. if err != nil {
  1169. return
  1170. }
  1171. //修改音频标题
  1172. sql2 := ` UPDATE report SET video_name=CONCAT(SUBSTRING_INDEX(video_name,"(",1),"` + videoNameDate + `") WHERE id = ? and (video_name !="" and video_name is not null)`
  1173. _, err = o.Raw(sql2, reportId).Exec()
  1174. return
  1175. }
  1176. func UpdateReportChapterPublishTime(reportId int, videoNameDate string) (err error) {
  1177. o := orm.NewOrmUsingDB("rddp")
  1178. sql1 := ` UPDATE report_chapter SET publish_time = NOW() WHERE report_id = ? `
  1179. _, err = o.Raw(sql1, reportId).Exec()
  1180. if err != nil {
  1181. return
  1182. }
  1183. //修改音频标题
  1184. 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)`
  1185. _, err = o.Raw(sql2, reportId).Exec()
  1186. return
  1187. }
  1188. // MarkEditReport 标记编辑英文研报的请求数据
  1189. type MarkEditReport struct {
  1190. ReportId int `description:"研报id"`
  1191. ReportChapterId int `description:"研报章节id"`
  1192. Status int `description:"标记状态,1:编辑中,2:查询状态,3:编辑完成"`
  1193. }
  1194. type MarkReportResp struct {
  1195. Status int `description:"状态:0:无人编辑, 1:当前有人在编辑"`
  1196. Msg string `description:"提示信息"`
  1197. Editor string `description:"编辑者姓名"`
  1198. }
  1199. type MarkReportItem struct {
  1200. AdminId int `description:"编辑者ID"`
  1201. Editor string `description:"编辑者姓名"`
  1202. ReportClassifyNameFirst string
  1203. }
  1204. // GetReportByCondition 获取报告
  1205. func GetReportByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, isPage bool, startSize, pageSize int) (items []*Report, err error) {
  1206. o := orm.NewOrmUsingDB("rddp")
  1207. fields := `*`
  1208. if len(fieldArr) > 0 {
  1209. fields = strings.Join(fieldArr, ",")
  1210. }
  1211. sql := `SELECT ` + fields + ` FROM report WHERE 1=1 `
  1212. sql += condition
  1213. order := ` ORDER BY modify_time DESC`
  1214. if orderRule != `` {
  1215. order = orderRule
  1216. }
  1217. sql += order
  1218. if isPage {
  1219. sql += ` LIMIT ?,?`
  1220. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1221. } else {
  1222. _, err = o.Raw(sql, pars).QueryRows(&items)
  1223. }
  1224. return
  1225. }
  1226. // ModifyReportMsgIsSendV2 更新报告消息状态
  1227. func ModifyReportMsgIsSendV2(reportId int) (err error) {
  1228. o := orm.NewOrmUsingDB("rddp")
  1229. sql := `UPDATE report SET msg_is_send = 1, ths_msg_is_send = 1, msg_send_time = NOW() WHERE id = ? LIMIT 1`
  1230. _, err = o.Raw(sql, reportId).Exec()
  1231. return
  1232. }
  1233. // SetPrePublishReportById 设置定时发布
  1234. func SetPrePublishReportById(reportId int, prePublishTime string, preMsgSend int) (err error) {
  1235. o := orm.NewOrmUsingDB("rddp")
  1236. sql := `UPDATE report SET pre_publish_time=?, pre_msg_send=? WHERE id = ? and state = 1 `
  1237. _, err = o.Raw(sql, prePublishTime, preMsgSend, reportId).Exec()
  1238. return
  1239. }
  1240. // ReportSubmitApproveReq 提交审批请求体
  1241. type ReportSubmitApproveReq struct {
  1242. ReportId int `description:"报告ID"`
  1243. }
  1244. // ReportCancelApproveReq 撤回审批请求体
  1245. type ReportCancelApproveReq struct {
  1246. ReportId int `description:"报告ID"`
  1247. }
  1248. func (m *Report) GetItemById(id int) (item *Report, err error) {
  1249. o := orm.NewOrmUsingDB("rddp")
  1250. sql := `SELECT * FROM report WHERE id = ? LIMIT 1`
  1251. err = o.Raw(sql, id).QueryRow(&item)
  1252. return
  1253. }
  1254. // GetReportStateCount 获取指定状态的报告数量
  1255. func GetReportStateCount(state int) (count int, err error) {
  1256. o := orm.NewOrmUsingDB("rddp")
  1257. sql := `SELECT COUNT(1) AS count FROM report WHERE state = ?`
  1258. err = o.Raw(sql, state).QueryRow(&count)
  1259. return
  1260. }
  1261. // UpdateReportsStateByCond 批量更新报告状态
  1262. func UpdateReportsStateByCond(classifyFirstId, classifySecondId, classifyThirdId, oldState, newState int) (err error) {
  1263. o := orm.NewOrmUsingDB("rddp")
  1264. cond := ``
  1265. if classifyFirstId > 0 {
  1266. cond += fmt.Sprintf(` AND classify_id_first = %d`, classifyFirstId)
  1267. }
  1268. if classifySecondId > 0 {
  1269. cond += fmt.Sprintf(` AND classify_id_second = %d`, classifySecondId)
  1270. }
  1271. if classifyThirdId > 0 {
  1272. cond += fmt.Sprintf(` AND classify_id_third = %d`, classifyThirdId)
  1273. }
  1274. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? %s`, cond)
  1275. _, err = o.Raw(sql, newState, oldState).Exec()
  1276. return
  1277. }
  1278. // UpdateReportsStateBySecondIds 批量更新二级分类报告状态
  1279. func UpdateReportsStateBySecondIds(oldState, newState int, secondIds []int) (err error) {
  1280. if len(secondIds) <= 0 {
  1281. return
  1282. }
  1283. o := orm.NewOrmUsingDB("rddp")
  1284. // (有审批流的)未发布->待提交
  1285. sql := fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1286. _, err = o.Raw(sql, newState, oldState, secondIds).Exec()
  1287. if err != nil {
  1288. return
  1289. }
  1290. // (无审批流的)待提交->未发布
  1291. sql = fmt.Sprintf(`UPDATE report SET state = ?, pre_publish_time = NULL WHERE state = ? AND classify_id_second NOT IN (%s)`, utils.GetOrmInReplace(len(secondIds)))
  1292. _, err = o.Raw(sql, oldState, newState, secondIds).Exec()
  1293. return
  1294. }
  1295. // GetReportPdfUrlReq 获取报告pdf地址请求体
  1296. type GetReportPdfUrlReq struct {
  1297. ReportUrl string `description:"报告Url"`
  1298. ReportCode string `description:"报告Code"`
  1299. Type int `description:"类型 1-pdf 2-图片"`
  1300. }
  1301. func ModifyReportPdfUrl(reportId int, detailPdfUrl string) (err error) {
  1302. o := orm.NewOrmUsingDB("rddp")
  1303. sql := `UPDATE report SET detail_pdf_url=? WHERE id=? `
  1304. _, err = o.Raw(sql, detailPdfUrl, reportId).Exec()
  1305. return
  1306. }
  1307. func ModifyReportImgUrl(reportId int, detailImgUrl string) (err error) {
  1308. o := orm.NewOrmUsingDB("rddp")
  1309. sql := `UPDATE report SET detail_img_url=? WHERE id=? `
  1310. _, err = o.Raw(sql, detailImgUrl, reportId).Exec()
  1311. return
  1312. }
  1313. func ModifyReportPdfUrlMobile(reportId int, detailPdfUrlMobile string) (err error) {
  1314. o := orm.NewOrmUsingDB("rddp")
  1315. sql := `UPDATE report SET detail_pdf_url_mobile=? WHERE id=? `
  1316. _, err = o.Raw(sql, detailPdfUrlMobile, reportId).Exec()
  1317. return
  1318. }
  1319. func ModifyReportImgUrlMobile(reportId int, detailImgUrlMobile string) (err error) {
  1320. o := orm.NewOrmUsingDB("rddp")
  1321. sql := `UPDATE report SET detail_img_url_mobile=? WHERE id=? `
  1322. _, err = o.Raw(sql, detailImgUrlMobile, reportId).Exec()
  1323. return
  1324. }
  1325. // UpdatePdfUrlReportById 清空pdf相关字段
  1326. func UpdatePdfUrlReportById(reportId int) (err error) {
  1327. o := orm.NewOrmUsingDB("rddp")
  1328. sql := `UPDATE report SET detail_img_url = '',detail_pdf_url='',modify_time=NOW() WHERE id = ? `
  1329. _, err = o.Raw(sql, reportId).Exec()
  1330. return
  1331. }
  1332. // InsertMultiReport
  1333. // @Description: 批量新增报告
  1334. // @author: Roc
  1335. // @datetime 2024-06-27 15:55:25
  1336. // @param items []*Report
  1337. // @return err error
  1338. func InsertMultiReport(items []*Report) (err error) {
  1339. o := orm.NewOrmUsingDB("rddp")
  1340. _, err = o.InsertMulti(500, items)
  1341. return
  1342. }
  1343. func GetReportListByCollectCount(classifyIdFirst, classifyIdSecond, classifyIdThird []string, keyword, author string, state int) (count int, err error) {
  1344. o := orm.NewOrmUsingDB("rddp")
  1345. var params []interface{}
  1346. // SQL 主体
  1347. sql := `
  1348. SELECT COUNT(DISTINCT t.id) AS totalCount
  1349. FROM (
  1350. SELECT b.id
  1351. FROM report AS b
  1352. LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_first
  1353. WHERE 1 = 1
  1354. `
  1355. // 处理 classifyIdFirst
  1356. if len(classifyIdFirst) > 0 {
  1357. sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdFirst)) + " ) "
  1358. for _, id := range classifyIdFirst {
  1359. params = append(params, id)
  1360. }
  1361. }
  1362. // 处理关键词
  1363. if keyword != "" {
  1364. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1365. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1366. }
  1367. if author != "" {
  1368. sql += " AND b.author = ? "
  1369. params = append(params, author)
  1370. }
  1371. if state > 0 {
  1372. sql += " AND b.state = ? "
  1373. params = append(params, state)
  1374. }
  1375. // 第二段 SQL
  1376. sql += `
  1377. UNION ALL
  1378. SELECT b.id
  1379. FROM report AS b
  1380. LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_second
  1381. WHERE 1 = 1
  1382. `
  1383. // 处理 classifyIdSecond
  1384. if len(classifyIdSecond) > 0 {
  1385. sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdSecond)) + " ) "
  1386. for _, id := range classifyIdSecond {
  1387. params = append(params, id)
  1388. }
  1389. }
  1390. // 处理关键词
  1391. if keyword != "" {
  1392. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1393. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1394. }
  1395. if author != "" {
  1396. sql += " AND b.author = ? "
  1397. params = append(params, author)
  1398. }
  1399. if state > 0 {
  1400. sql += " AND b.state = ? "
  1401. params = append(params, state)
  1402. }
  1403. // 第三段 SQL
  1404. sql += `
  1405. UNION ALL
  1406. SELECT b.id
  1407. FROM report AS b
  1408. LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_third
  1409. WHERE 1 = 1
  1410. `
  1411. // 处理 classifyIdThird
  1412. if len(classifyIdThird) > 0 {
  1413. sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdThird)) + " ) "
  1414. for _, id := range classifyIdThird {
  1415. params = append(params, id)
  1416. }
  1417. }
  1418. // 处理关键词
  1419. if keyword != "" {
  1420. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1421. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1422. }
  1423. if author != "" {
  1424. sql += " AND b.author = ? "
  1425. params = append(params, author)
  1426. }
  1427. if state > 0 {
  1428. sql += " AND b.state = ? "
  1429. params = append(params, state)
  1430. }
  1431. sql += ") AS t"
  1432. // 执行 SQL 查询获取总数
  1433. err = o.Raw(sql, params...).QueryRow(&count)
  1434. return count, err
  1435. }
  1436. func GetReportListByCollectList(classifyIdFirst, classifyIdSecond, classifyIdThird []string, keyword, orderField, orderType string, startSize, pageSize int, author string, state int) (items []*ReportList, err error) {
  1437. o := orm.NewOrmUsingDB("rddp")
  1438. var params []interface{}
  1439. // SQL 主体
  1440. sql := `
  1441. SELECT DISTINCT t.id, t.title, t.author, t.modify_time, t.publish_time
  1442. FROM (
  1443. SELECT b.id, b.title, b.author, b.modify_time, b.publish_time
  1444. FROM report AS b
  1445. LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_first
  1446. WHERE 1 = 1
  1447. `
  1448. // 处理 classifyIdFirst
  1449. if len(classifyIdFirst) > 0 {
  1450. sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdFirst)) + " ) "
  1451. for _, id := range classifyIdFirst {
  1452. params = append(params, id)
  1453. }
  1454. }
  1455. // 处理关键词
  1456. if keyword != "" {
  1457. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1458. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1459. }
  1460. if author != "" {
  1461. sql += " AND b.author = ? "
  1462. params = append(params, author)
  1463. }
  1464. if state > 0 {
  1465. sql += " AND b.state = ? "
  1466. params = append(params, state)
  1467. }
  1468. // 第二段 SQL
  1469. sql += `
  1470. UNION ALL
  1471. SELECT b.id, b.title, b.author, b.modify_time, b.publish_time
  1472. FROM report AS b
  1473. LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_second
  1474. WHERE 1 = 1
  1475. `
  1476. // 处理 classifyIdSecond
  1477. if len(classifyIdSecond) > 0 {
  1478. sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdSecond)) + " ) "
  1479. for _, id := range classifyIdSecond {
  1480. params = append(params, id)
  1481. }
  1482. }
  1483. // 处理关键词
  1484. if keyword != "" {
  1485. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1486. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1487. }
  1488. if author != "" {
  1489. sql += " AND b.author = ? "
  1490. params = append(params, author)
  1491. }
  1492. if state > 0 {
  1493. sql += " AND b.state = ? "
  1494. params = append(params, state)
  1495. }
  1496. // 第三段 SQL
  1497. sql += `
  1498. UNION ALL
  1499. SELECT b.id, b.title, b.author, b.modify_time, b.publish_time
  1500. FROM report AS b
  1501. LEFT JOIN user_collect_classify AS a ON a.classify_id = b.classify_id_third
  1502. WHERE 1 = 1
  1503. `
  1504. // 处理 classifyIdThird
  1505. if len(classifyIdThird) > 0 {
  1506. sql += " AND a.classify_id IN ( " + utils.GetOrmInReplace(len(classifyIdThird)) + " ) "
  1507. for _, id := range classifyIdThird {
  1508. params = append(params, id)
  1509. }
  1510. }
  1511. // 处理关键词
  1512. if keyword != "" {
  1513. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1514. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1515. }
  1516. if author != "" {
  1517. sql += " AND b.author = ? "
  1518. params = append(params, author)
  1519. }
  1520. if state > 0 {
  1521. sql += " AND b.state = ? "
  1522. params = append(params, state)
  1523. }
  1524. sql += ") AS t "
  1525. // 排序处理
  1526. if orderField != "" && orderType != "" {
  1527. sql += " ORDER BY " + orderField + " " + orderType
  1528. } else {
  1529. sql += " ORDER BY t.modify_time DESC, t.publish_time DESC "
  1530. }
  1531. // 分页
  1532. sql += " LIMIT ?, ?"
  1533. params = append(params, (startSize-1)*pageSize, pageSize)
  1534. // 执行 SQL 查询
  1535. _, err = o.Raw(sql, params...).QueryRows(&items)
  1536. return items, err
  1537. }
  1538. func GetReportListByCollectCountV2(classifyIdFirst, classifyIdSecond, classifyIdThird, chartPermissionIdList []string, keyword, author string, isPublic int, stateArr []int) (count int, err error) {
  1539. o := orm.NewOrmUsingDB("rddp")
  1540. var params []interface{}
  1541. // SQL 主体
  1542. sql := `
  1543. SELECT COUNT(DISTINCT t.id) AS totalCount
  1544. FROM (
  1545. SELECT b.id
  1546. FROM report AS b WHERE 1 = 1
  1547. `
  1548. if len(chartPermissionIdList) > 0 {
  1549. classifyIds, e := GetClassifyIdsByPermissionId(chartPermissionIdList)
  1550. if e != nil {
  1551. err = e
  1552. return
  1553. }
  1554. if len(classifyIds) > 0 {
  1555. sql += ` AND ( (b.classify_id_first IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) AND b.classify_id_second = 0)
  1556. OR (b.classify_id_second IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) AND b.classify_id_third = 0)
  1557. OR b.classify_id_third IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) )`
  1558. for _, classifyId := range classifyIds {
  1559. params = append(params, classifyId)
  1560. }
  1561. for _, classifyId := range classifyIds {
  1562. params = append(params, classifyId)
  1563. }
  1564. for _, classifyId := range classifyIds {
  1565. params = append(params, classifyId)
  1566. }
  1567. }
  1568. }
  1569. // 处理关键词
  1570. if keyword != "" {
  1571. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1572. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1573. }
  1574. if author != "" {
  1575. sql += " AND b.author = ? "
  1576. params = append(params, author)
  1577. }
  1578. if isPublic > 0 {
  1579. sql += " AND b.is_public_publish = ? "
  1580. params = append(params, isPublic)
  1581. }
  1582. if len(stateArr) > 0 {
  1583. sql += fmt.Sprintf(" AND b.state IN (%s)", utils.GetOrmInReplace(len(stateArr)))
  1584. params = append(params, stateArr)
  1585. }
  1586. // 分类id判断
  1587. classifyIdSqlList := make([]string, 0)
  1588. // 处理 classifyIdFirst
  1589. if len(classifyIdFirst) > 0 {
  1590. classifyIdSqlList = append(classifyIdSqlList, " ( b.classify_id_first IN ( "+utils.GetOrmInReplace(len(classifyIdFirst))+" ) AND classify_id_second = 0 AND classify_id_third = 0 ) ")
  1591. for _, id := range classifyIdFirst {
  1592. params = append(params, id)
  1593. }
  1594. }
  1595. // 处理 classifyIdSecond
  1596. if len(classifyIdSecond) > 0 {
  1597. classifyIdSqlList = append(classifyIdSqlList, " ( b.classify_id_second IN ( "+utils.GetOrmInReplace(len(classifyIdSecond))+" ) AND classify_id_third = 0) ")
  1598. for _, id := range classifyIdSecond {
  1599. params = append(params, id)
  1600. }
  1601. }
  1602. // 处理 classifyIdThird
  1603. if len(classifyIdThird) > 0 {
  1604. classifyIdSqlList = append(classifyIdSqlList, " ( b.classify_id_third IN ( "+utils.GetOrmInReplace(len(classifyIdThird))+" ) ) ")
  1605. for _, id := range classifyIdThird {
  1606. params = append(params, id)
  1607. }
  1608. }
  1609. if len(classifyIdSqlList) > 0 {
  1610. sql += ` AND (` + strings.Join(classifyIdSqlList, " OR ") + `) `
  1611. }
  1612. sql += ") AS t"
  1613. // 执行 SQL 查询获取总数
  1614. err = o.Raw(sql, params...).QueryRow(&count)
  1615. return count, err
  1616. }
  1617. func GetReportListByCollectListV2(classifyIdFirst, classifyIdSecond, classifyIdThird, chartPermissionIdList []string, keyword, orderField, orderType string, startSize, pageSize int, author string, isPublic int, stateArr []int) (items []*ReportList, err error) {
  1618. o := orm.NewOrmUsingDB("rddp")
  1619. var params []interface{}
  1620. // SQL 主体
  1621. sql := `
  1622. SELECT DISTINCT t.id, t.title, t.author, t.modify_time, t.publish_time,t.classify_id_first,t.classify_name_first,
  1623. t.classify_id_second,t.classify_name_second,t.classify_id_third,t.classify_name_third,
  1624. t.abstract,t.admin_id,t.admin_real_name,t.last_modify_admin_id,t.last_modify_admin_name
  1625. FROM (
  1626. SELECT b.id, b.title, b.author, b.modify_time, b.publish_time,b.classify_id_first,b.classify_name_first,
  1627. b.classify_id_second,b.classify_name_second,b.classify_id_third,b.classify_name_third,
  1628. b.abstract,b.admin_id,b.admin_real_name,b.last_modify_admin_id,b.last_modify_admin_name
  1629. FROM report AS b WHERE 1 = 1
  1630. `
  1631. // 处理关键词
  1632. if keyword != "" {
  1633. sql += " AND (b.title LIKE ? OR b.admin_real_name LIKE ?)"
  1634. params = append(params, "%"+keyword+"%", "%"+keyword+"%")
  1635. }
  1636. if author != "" {
  1637. sql += " AND b.author = ? "
  1638. params = append(params, author)
  1639. }
  1640. if isPublic > 0 {
  1641. sql += " AND b.is_public_publish = ? "
  1642. params = append(params, isPublic)
  1643. }
  1644. if len(stateArr) > 0 {
  1645. sql += fmt.Sprintf(" AND b.state IN (%s)", utils.GetOrmInReplace(len(stateArr)))
  1646. params = append(params, stateArr)
  1647. }
  1648. // 分类id判断
  1649. classifyIdSqlList := make([]string, 0)
  1650. // 处理 classifyIdFirst
  1651. if len(classifyIdFirst) > 0 {
  1652. classifyIdSqlList = append(classifyIdSqlList, " ( b.classify_id_first IN ( "+utils.GetOrmInReplace(len(classifyIdFirst))+" ) AND classify_id_second = 0 AND classify_id_third = 0 ) ")
  1653. for _, id := range classifyIdFirst {
  1654. params = append(params, id)
  1655. }
  1656. }
  1657. // 处理 classifyIdSecond
  1658. if len(classifyIdSecond) > 0 {
  1659. classifyIdSqlList = append(classifyIdSqlList, " ( b.classify_id_second IN ( "+utils.GetOrmInReplace(len(classifyIdSecond))+" ) AND classify_id_third = 0) ")
  1660. for _, id := range classifyIdSecond {
  1661. params = append(params, id)
  1662. }
  1663. }
  1664. // 处理 classifyIdThird
  1665. if len(classifyIdThird) > 0 {
  1666. classifyIdSqlList = append(classifyIdSqlList, " ( b.classify_id_third IN ( "+utils.GetOrmInReplace(len(classifyIdThird))+" ) ) ")
  1667. for _, id := range classifyIdThird {
  1668. params = append(params, id)
  1669. }
  1670. }
  1671. if len(classifyIdSqlList) > 0 {
  1672. sql += ` AND (` + strings.Join(classifyIdSqlList, " OR ") + `) `
  1673. }
  1674. if len(chartPermissionIdList) > 0 {
  1675. classifyIds, e := GetClassifyIdsByPermissionId(chartPermissionIdList)
  1676. if e != nil {
  1677. err = e
  1678. return nil, err
  1679. }
  1680. if len(classifyIds) > 0 {
  1681. sql += ` AND ( (b.classify_id_first IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) AND b.classify_id_second = 0)
  1682. OR (b.classify_id_second IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) AND b.classify_id_third = 0)
  1683. OR b.classify_id_third IN (` + utils.GetOrmInReplace(len(classifyIds)) + `) )`
  1684. for _, classifyId := range classifyIds {
  1685. params = append(params, classifyId)
  1686. }
  1687. for _, classifyId := range classifyIds {
  1688. params = append(params, classifyId)
  1689. }
  1690. for _, classifyId := range classifyIds {
  1691. params = append(params, classifyId)
  1692. }
  1693. }
  1694. }
  1695. sql += ") AS t "
  1696. // 排序处理
  1697. if orderField != "" && orderType != "" {
  1698. sql += " ORDER BY " + orderField + " " + orderType
  1699. } else {
  1700. sql += " ORDER BY t.modify_time DESC, t.publish_time DESC "
  1701. }
  1702. // 分页
  1703. sql += " LIMIT ?, ?"
  1704. params = append(params, (startSize-1)*pageSize, pageSize)
  1705. // 执行 SQL 查询
  1706. _, err = o.Raw(sql, params...).QueryRows(&items)
  1707. return items, err
  1708. }
  1709. type ReportShartUrlReq struct {
  1710. Url string `description:"分享链接"`
  1711. ReportId int `description:"报告ID"`
  1712. }
  1713. type ReportShartUrlResp struct {
  1714. UrlToken string `description:"分享链接token"`
  1715. }