report.go 68 KB

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