report.go 67 KB

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