report.go 66 KB

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