report.go 59 KB

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